Wednesday, October 5, 2011

Copy List data in to Dictionary

If you need to add Data to Dictionary now it’s easy because of LINQ in following code I have Illustrate it. In that I have retrieve data from CRM Entity call interest and I have add ID and Name to dictionary.



public Dictionary<Guid,string> GetAllInterest()
{
 Dictionary<Guid, string> dictionary = new Dictionary<Guid, string>();
 try
 {
   List<interest> interestList = (from a in QueryProvider.Linq<interest>()
                           select a).ToList<interest>();
   interestList.ForEach(x => { dictionary.Add(x.interestid.Value, x.name); });
 }
 catch (Exception ex){}
 return dictionary;           
}

You will be able to develop the above code and use it thank you.

0 comments:

Post a Comment