This project has moved. For the latest updates, please go here.

Accessing navigation properties through Include()

Mar 2, 2015 at 3:48 PM
Edited Mar 2, 2015 at 4:28 PM
We have some problems getting the navigation properties loaded with "."Include", these are actually null (we traced the sql query generated by the entity framework for accessing the database, and the navigation property does not appear into it) in this case.
When we explicitly select the navigation property from the entity, as an anonymous datatype, the navigation property is read correctly and not null.
In the navigation properties samples there is a "queryExpression.ExecuteWithEntityFramework()" call on wcf server side, instead of the usual "queryExpression.Execute()". What is the difference between the both ?
Are there 2 different "Include" implementations available, one in Remote.Linq and one in Remote.Linq.EntityFramework ?
The handling of the "Include()" functions by the wcf client is one of the new features in RemoteLinq 4.0.0, is that correct ?
Mar 8, 2015 at 9:27 PM
Yes you’re right, ‘Include’ is a new feature of remote.linq 4.0.0

And you’re also right in that you need to use method queryExpression.ExecuteWithEntityFramework() available from Remote.Linq.EntityFramework package in order to have Include applied to entity framework queries.

The reason is that include is not part of generic linq but comes as a specific feature of entity framework. Even thought, remote.linq supports query composition with include on client side it requires special handling on server side – e.g. using Remote.Linq.EntityFramework – to actually take effect.
Mar 9, 2015 at 8:48 AM
Edited Mar 9, 2015 at 8:49 AM
Thank you for the clarification.
I first tried this
  var efContext = new EFContext();
  var result = queryExpression.ExecuteWithEntityFramework(queryableProvider: type => efContext.Set(type));
but did not work.

The "Include" handling on server side worked first after changing the code like this
   var efContext = new EFContext();
   var result = queryExpression.ExecuteWithEntityFramework(efContext);

Mar 9, 2015 at 1:37 PM
Ah yes, I think method DbContext.Set(Type) doesn't handle include properly. Maybe I should make the first overload of the method ExecuteWithEntityFramework private to avoid people run into this issue.

Using the generic version DbContext.Set<TEntity>() should work.