Map a List to a Grouped DTO
See original GitHub issueI have a list of entities and I need to map it to a DTO, but grouped.
My entity Class:
Class myEntity
{
public int id {get;set;}
public double cost {get;set;}
}
My DTO Class
Class myEntityDTO
{
public int id {get;set;}
public double cost {get;set;}
}
My mapping:
CreateMap<myEntity, myEntityDTO>()
//register all properties mapped
;
var entities = new List<myEntity>();
// fill the list
// [
// {1,50},
// {1,30},
// {1,25},
// {2,80},
// {2,20},
// {2,45},
// {2,38},
// {3,10},
// {3,15}
// ]
Mapper.Map<List<myEntityDTO>>(entities);
I need to group my list of myEntity (by id for example, and sum cost), so, my DTO should be like this: [ {id: 1, cost: 105}, {id: 2, cost: 183}, {id: 3, cost: 25} ]
I hope I made myself clear, my english is not good.
Thanks in advance. Regards!
Issue Analytics
- State:
- Created 6 years ago
- Comments:14 (7 by maintainers)
Top Results From Across the Web
Group List to List DTO using Java 8
I would like to group a list of InscricaoTipoTrabalhoAvaliador in a DTO by equal AvaliadorEvento using JAVA 8. Could someone help? Bank query ......
Read more >Java Streams: The Dynamic Grouping Solution You've ...
Grouping data is a common task when working with streams in Java. It allows us to group ... Step 1 :Creating a map...
Read more >How to Convert List to Map in Java
Learn about different ways of converting a List to a Map in Java, using core functionalities and some popular libraries.
Read more >10 Examples of Converting a List to Map in Java 8
groupingBy() method to group elements in Set and In this article, we will use Collectors.toMap() method to convert a List of an object...
Read more >groupBy - Kotlin Programming Language
Groups elements of the original array by the key returned by the given ... a map where each group key is associated with...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Even for mapping the grouping to the DTO, I still think AM wouldn’t be that useful because then you would have to customize the default map and it’s not auto anymore, is it? Just LINQ seems the best.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.