O'Reilly Forums: Dbcontext Query Nav Property - O'Reilly Forums
Page 1 of 1
Dbcontext Query Nav Property Page 39 Example 2-27
Posted 01 April 2012 - 07:42 PM
Question regarding querying the contents of a collection navigation property from the DbContext book, page 39. I was playing around with the query for example 2-27 In-memory query of a navigation property. I wanted to see if it could all be done in one go. So I tried......
var query = from d in context.Destinations
let temp1 = context.Destinations.Where(a => a.Name == "Grand Canyon").Select(a => a)
let temp2 = temp1.Single()
let temp3 = context.Entry(temp2).Collection(b => b.Lodgings).Query()
from x in temp3
where x.MilesFromNearestAirport <= 10
TargetParameterCountException, parameter count mismatch. My first question is, what is causing the exception and second, would it even be possible to do this all in one go?
Posted 21 April 2012 - 02:07 PM
I'm not sure about the error without doing the same experiments myself.
I'm also not familiar with "let" outside of linq.
I'd get rid of the first line of code that returns query.
Then (off the top of my head...check the book for syntax)
var dest= context.Destinations.Where(a => a.Name == "Grand Canyon").Select(a => a).FirstOrSingle();
var lodgings=context.Entry(dest).Collection(b => b.Lodgings).Query().Where(l=>l.MilesFromNearestAirport <= 10).Load();
No you can't combine them.Eager loading does not support filtering on navigation properties.
Share this topic:
Page 1 of 1
1 User(s) are reading this topic