I am trying to use LINQ/LAMBDA access a property
List<Latest> latestBooks = DataContext.Session.Query<Book>().Where(x=> x.Enabled == "True" ).Select(x => new Latest(x.Title,x.Author)).Take(10).ToList();
But there is another property defined in the Book class that look like this:
public virtual string FrontEndLink { get { return string.Format("http://myurl/{0}", Filename); } }
When I try this
List<Latest> latestBooks = DataContext.Session.Query<Book>().Where(x=> x.Enabled == "True" ).Select(x => new Latest(x.FrontEndLink)).Take(10).ToList();
The code breaks and give me an error:
Could not resolve property: Quote((x, ) => (x.Id)), ), Quote((x, ) => (new Latest(x.FrontEndLink, ))), ), p1, )]
LINQ to Entities is trying to convert everything before the
ToListinto SQL – and it won’t be able to do that with yourFrontEndLinkproperty. You want to do that bit in LINQ to Objects, but after filtering to only 10 results. So I’d use: