entity framework 5 - Trying to pass back the results of a LINQ query from a middle tier class -
i need feature...
the first query works fine:
public list<project> getprojectbycustomerid(int16 customerid) { try { using (yeagertechentities dbcontext = new yeagertechentities()) { dbcontext.configuration.proxycreationenabled = false; dbcontext.database.connection.open(); ienumerable<project> project = dbcontext.projects.where(p => p.customerid == customerid); list<project> myprojects = new list<project>(); myprojects = project.tolist(); return myprojects; } } catch (exception ex) { throw ex; } }
the second query has project list , want bring columns in query, giving me error: "cannot convert type iqueryable anonymoustype#1 generic.list". design time compile error on entire sql statement right before "(s =>"
public list<project> getprojectbycustomerid(int16 customerid) { try { using (yeagertechentities dbcontext = new yeagertechentities()) { dbcontext.configuration.proxycreationenabled = false; dbcontext.database.connection.open(); list<project> myprojects = new list<project>(); myprojects = dbcontext.projects.include("timetrackings").where(p => p.customerid == customerid && p.category.categoryid == 5 && p.customer.city == "ny" && p.status.statusid == 1 && p.priority.priorityid == 2).select(s => new { pridesc = s.priority.description, s.notes, stadesc = s.status.description }); return myprojects; } } catch (exception ex) { throw ex; } }
the third query allows me select columns need. whole query fine, except can't pass "project" variable. design time compile error of: "cannot convert type generic.list.anonymoustype#1 generic.list "
public list<string> getprojectbycustomerid(int16 customerid) { try { using (yeagertechentities dbcontext = new yeagertechentities()) { dbcontext.configuration.proxycreationenabled = false; dbcontext.database.connection.open(); var project = dbcontext.projects.include("timetrackings").where(p => p.customerid == customerid && p.category.categoryid == 5 && p.customer.city == "ny" && p.status.statusid == 1 && p.priority.priorityid == 2).select(s => new { pridesc = s.priority.description, s.notes, stadesc = s.status.description }).tolist(); return project; } } catch (exception ex) { throw ex; } }
what correct way (syntax wise well) pass second , third queries?
i know can third query right in code-behind , bind grid "var" variable datasource. however, i appreciate if can inform me how can pass second , third query types front end middle tier class.
you're creating anonymous types in select
methods, not string
s or project
s. first query works because you're returning list<project>
.
if don't want entire project, subset of fields, create new class holds fields need, , use in select()
instead of creating anonymous type. illustration of technique, see here.
Comments
Post a Comment