How do I make this Query against EF Efficient?
- by dudeNumber4
Using EF4. Assume I have this:
IQueryable<ParentEntity> qry = myRepository.GetParentEntities();
Int32 n = 1;
What I want to do is this, but EF can't compare against null.
qry.Where( parent => parent.Children.Where( child => child.IntCol == n ) != null )
What works is this, but the SQL it produces (as you would imagine) is pretty inefficient:
qry.Where( parent => parent.Children.Where( child => child.IntCol == n ).FirstOrDefault().IntCol == n )
How can I do something like the first comparison to null that won't be generating nested queries and so forth?