Returning a LINQ query
-
Hi peeps, This is probably a easy question for someone to answer. What I've done is to encapsulate all my LINQ queries in a class, and then the UI calls that classes methods to obtain data. So In the DataContextClass I have got a method that returns the result of a query, but what do I make the return type of the method itslef??? Notice that the query returns 2 classes - the QuickLink class, and User class.
public ??????????? GetSingleLink(){ . . . return( (from lnk in db.QuickLinks where lnk.LinkID == checkDataLink.LinkID select new { LinkID = lnk.LinkID, Url = lnk.Url, CreatedByUser = lnk.CreatedByUser, User = from u in db.Users select new{ UserID = lnk.CreatedByUser, Email = u.Email }, CreatedDate = lnk.CreatedDate, }) ); }
This is driving me nuts :wtf: :omg: -
Hi peeps, This is probably a easy question for someone to answer. What I've done is to encapsulate all my LINQ queries in a class, and then the UI calls that classes methods to obtain data. So In the DataContextClass I have got a method that returns the result of a query, but what do I make the return type of the method itslef??? Notice that the query returns 2 classes - the QuickLink class, and User class.
public ??????????? GetSingleLink(){ . . . return( (from lnk in db.QuickLinks where lnk.LinkID == checkDataLink.LinkID select new { LinkID = lnk.LinkID, Url = lnk.Url, CreatedByUser = lnk.CreatedByUser, User = from u in db.Users select new{ UserID = lnk.CreatedByUser, Email = u.Email }, CreatedDate = lnk.CreatedDate, }) ); }
This is driving me nuts :wtf: :omg:public IQueryable<QuickLink> GetSingleLink(){ . . . return( (from lnk in db.QuickLinks where lnk.LinkID == checkDataLink.LinkID select new QuickLink() { LinkID = lnk.LinkID, Url = lnk.Url, CreatedByUser = lnk.CreatedByUser, User = from u in db.Users select new User() { UserID = lnk.CreatedByUser, Email = u.Email }, CreatedDate = lnk.CreatedDate, }) ); } Cheers! Al
- Is God willing to prevent evil, but not able? Then he is impotent. - Is he able, but not willing? Then he is malevolent. - Is he both able and willing? Whence then is evil? - Is he neither able nor willing? Then why call him God? Epicurus
-
public IQueryable<QuickLink> GetSingleLink(){ . . . return( (from lnk in db.QuickLinks where lnk.LinkID == checkDataLink.LinkID select new QuickLink() { LinkID = lnk.LinkID, Url = lnk.Url, CreatedByUser = lnk.CreatedByUser, User = from u in db.Users select new User() { UserID = lnk.CreatedByUser, Email = u.Email }, CreatedDate = lnk.CreatedDate, }) ); } Cheers! Al
- Is God willing to prevent evil, but not able? Then he is impotent. - Is he able, but not willing? Then he is malevolent. - Is he both able and willing? Whence then is evil? - Is he neither able nor willing? Then why call him God? Epicurus
Thanks for taking the time to reply mate, but I've just figured it out! It was a long day, doing to many things at once, and I suffer from a rare stupidity based disease called 'Code blindness'. ;)