O'Reilly Forums: Dbcontext Query Nav Property - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Dbcontext Query Nav Property Page 39 Example 2-27

#1 User is offline   whaley8991 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 01-April 12

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
select x;

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?

#2 User is offline   JulieLerman 

  • Advanced Member
  • PipPipPipPipPipPipPipPip
  • Group: O'Reilly Author
  • Posts: 334
  • Joined: 17-September 08

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
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users