Mayank Pathak
Mayank Pathak

Reputation: 3681

Return Dictionary<int,List<Int>> from EntityFramework table

I need to select Dictionary<Int32, List<Int32>> from EntityFramework table. I am using below query but unable to make it work to result as Dictionary.

 var result= _dbNavigation.BudgetRevenueMileStones
                          .ToDictionary(kvp => kvp.BRMTaskTemplateID.Value
                                            , value => value.BRMTaskID.Value );

The table structure is like below.

ID  BRMTaskID   BRMTaskTemplateID
708 309880       6268   
709 309893       6268   
710 309925       6268   
711 301111       6255

Expected output is(as Dictionary<Int,List<Int>>)

6268, 309880,309893,309925
6255, 301111

Upvotes: 2

Views: 3094

Answers (1)

Selman Gen&#231;
Selman Gen&#231;

Reputation: 101701

You can group your records based on BRMTaskTemplateID

var result= _dbNavigation.BudgetRevenueMileStones 
             .GroupBy(x => x.BRMTaskTemplateID)
             .ToDictionary(g => g.Key,
                           g => g.Select(x => x.BRMTaskID).ToList());

Upvotes: 5

Related Questions