AJAY KUMAR SANTRA

AJAY KUMAR SANTRA

  • NA
  • 14
  • 2.6k

How to map a List<Dictionary<enum, string>> to List<object>?

Oct 14 2014 7:25 AM
List<ProjectCounterEntities> lstResult = new List<ProjectCounterEntities>();
 
List<Dictionary<ProjectStates, string>> lstProjectCount = new List<Dictionary<ProjectStates, string>>();
lstProjectCount
= objClient.GetProjectCounter();
if (lstProjectCount != null)
 { Dictionary<ProjectStates, string> dicResult = new Dictionary<ProjectStates, string>();
dicResult
= lstProjectCount.ToDictionary(dicResult);
   foreach (var k in dicResult)
 {
objProCount
= new ProjectCounterEntities();
    objProCount.ProjectState = (ProjectStateEnumUI)k.Key;
objProCount
.ProjectCount = k.Value;
lstResult
.Add(objProCount);
 }
return lstResult; }

I want to retrive value with respact to key , and want to map the value and key both into the DTO List<ProjectCounterEntities>, where ProjectCounterEntities is a DTO and the members of this DTO are "ProjectState" and "Count".

The output of List<ProjectCounterEntities> will be

ProjectState      Count
 
------------------------
projectstate1
2
Projectstate2    5
ProjectState3      6