Return Linq query results into List object

entity-framework linq

Accepted Answer

Select() and Where() will be backIQueryable<T> , notList<T> You must transform it into aList<T> - which carries out the query (instead of just preparing it).

All you have to do is dialToList() after the inquiry. For instance:

// There's no need to declare the variable separately...
List<AgentProductTraining> productTraining = (from records in db.CourseToProduct
                                              where records.CourseCode == course.CourseCode
                                              select records).ToList();

However, if all you're doing is a single query, I personally wouldn't recommend using a query expression.Where clause:

// Changed to var just for convenience - the type is still List<AgentProductTraining>
var productTraining = db.CourseToProduct
                        .Where(records => records.CourseCode == course.CourseCode)
                        .ToList();
13
1/31/2013 10:29:09 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow