Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
List<projectcounterentities> lstResult = new List<projectcounterentities>();
List<dictionary><projectstates,string>> lstProjectCount = new List<dictionary><projectstates,string>>();
lstProjectCount = objClient.GetProjectCounter();
if (lstProjectCount != null)
{
    var dicResult = new Dictionary<projectstates,string>();
    dicResult = lstProjectCount.ToDictionary();
    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
Posted
Updated 14-Oct-14 20:35pm
v2

Hi once try this code
i created enum and class which is having two properties

public enum projectstates
   {
       projectstate1 = 1,
       projectstate2 = 2,
       projectstate3 = 3,
       projectstate4 = 4
   }

   public class projectcounterentities
   {
       public string ProjectState { get; set; }
       public string count { get; set; }
   }



 List<dictionary><projectstates,>> list = new List<dictionary><projectstates,>>()
           {
               new Dictionary<projectstates,>() { { projectstates.projectstate1, "3" }, { projectstates.projectstate3, "75" } },
               new Dictionary<projectstates,>() { { projectstates.projectstate4, "3" }, { projectstates.projectstate2, "15" } }
           };

           List<projectcounterentities> projectcounterentities = new List<projectcounterentities>();

           foreach (var item in list)
           {
               projectcounterentities.AddRange(item.Select(h => new projectcounterentities() { count = h.Value, ProjectState = h.Key.ToString() }));
           }
 
Share this answer
 
v3
Comments
Ajay Kumar 15-Oct-14 3:13am    
It is working successfully . Many Many thanks....
BillWoodruff 20-Oct-14 12:12pm    
+5 Nice work !
Samatha Reddy G 22-Oct-14 2:03am    
thank you
 
Share this answer
 
v2
Comments
Ajay Kumar 15-Oct-14 2:53am    
Thank you for your suggestion. but i think you did't getting me actually i want to map the Inner dictionary of a list to some other dictionary or a list.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900