I am working on a new project, and we are using the Entity Framework, and the dev developer, if possible, would like to use lambda queries. One thing that we find difficult to determine is to select two columns. Also how to choose a separate one. We have a table with several records for the provider, but we just want to get the list of suppliers and load the dictionary object. It fails because, as it is written, it tries to add the key value that has already been added. Take the following query.
Dictionary<int, string> dict = new Dictionary<int, string>();
dict = GetWamVendorInfo().AsEnumerable()
.Where(x => x.vendor_name != null && x.vendor_id != null)
.Take(2)
.ToDictionary(o => int.Parse(o.vendor_id.ToString()), o => o.vendor_name);
What I would like to do is select only vendor_id and vendor_name so that we can only get individual records.
Any help would be greatly appreciated.
Thank,
Rhonda