c# - reading the result of LINQ query using Datarow -


how can read reult of linq query row row .(is possible)? want implemente 1 doesn't possible:

aspnetdbdatacontext aspdb = new aspnetdbdatacontext(); var res = r in aspdb.routelinqs           r.userid == userid           select r;  foreach (datarow row in res) {     // ... 

an exception thrown:

cannot convert type 'quickroutes.dal.routelinq' 'system.data.datarow'

edit:

in foreach block have:

foreach (var row in res) {     var routeid = (int)row["routeid"];     var route = new route(routeid)                 {                     name = (string)row["sourcename"],                     time = row["creationtime"] dbnull ? new datetime() :                                     convert.todatetime(row["creationtime"])                 };      route.trackpoints = gettrackpointsforroute(routeid);     result.add(route); } 

if use var error in lines occure:

cannot apply indexing [] expression of type 'quickroutes.dal.routelinq'

use

foreach (routelinq row in res) {     // ... 

or simply:

foreach (var row in res) {     // ... 

your linq query doesnt return collection of datarow objects, instead objects of class autogenerated database table name.

edit, account edit in question:

why accessing members of objects still datarow objects?

you want access like:

int routeid = row.routeid; 

i recommend @ few basic linq-to-sql (or orm in general) tutorials.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -