Accepted answer

i figured it out, thanks for the suggestions anyway. the solution is to do this (2nd attempt in my question):

var qry = (from a in actions
join u in users on a.userid equals u.userid    
select a).include("user")

the reason intellisense didn't show include after the query was because i needed the following using:


everything worked fine doing this.


i use for this the loadwith option

var dataoptions = new;
dataoptions.loadwith<action>(ac => as.user);
ctx.loadoptions = dataoptions;

thats it. ctx is your datacontext. this works for me :-)


doing the basic query mentioned in your posted question you won't be able to see the user properties unless you return an anonymous type as following:

from a in actions
join u in users on a.userid equals u.userid
select new
   actionuserid = a.userid
   userproperty1 = u.userid

however to use the include method on the objectcontext you could use the following:

make sure you have lazyloading off by using the following line:

entities.contextoptions.lazyloadingenabled = false;

then proceed by

var bar = entities.actions.include("user");
var foo = (from a in bar
           select a);


if what you want is a query that will return all action entities whose associated user entity actually exists via the action.userid foreign key property, this will do it:

var results = context.actions
    .where(action =>
        context.users.any(user =>
            user.userid == action.userid));

however you don't have to use foreign key properties in order to do filtering, since you also have navigation properties. so your query can be simplified by filtering on the action.user navigation property instead, like in this example:

var results = context.actions
    .where(action => action.user != null);

if your model states that the action.user property can never be null (i.e. the action.userid foreign key is not nullable in the database) and what you want is actually all action entities with their associated users, then the query becomes even simpler

var results = context.actions.include("user");


better, refactor friendly code (ef6)

var x = (from cart in context.shoppingcarts
         where == 123
         select cart).include(t => t.cartitems);


var x = from cart in context.shoppingcarts.include(nameof(shoppingcart.cartitems))
        where == 123
        select cart;

update 3/31/2017

you can also use include in lambda syntax for either method:

var x = from cart in context.shoppingcarts.include(p => p.shoppingcart.cartitems))
        where == 123
        select cart;

Related Query