I have been trying to figure out how to get values from database table to dictionary using LINQ. However I'm unable to understand the syntax. My requirement is the following:
1) Call the method in DAL from codebehind
2) Get only ID and Name from database
My code looks like the following (although this doesn't work):
ASCX.CS
Dictionary<int,string> peopleInformation = new Dictionary<int, string>();
peopleInformation = myContext.GetAgeAndName(id);
DAL:
public Dictionary<int,string> GetAgeAndName(int personID)
{
Dictionary<int, string> people = (from l in this.PeopleInfos
where l.ID == personID select l).ToDictionary<int,string>(l => l.ID, l => l.Name);
return people;
}
How to proceed with this query, what is the correct syntax?