Question

Say my object graph looks like:

User
 => Friends
   => Clicks
     => Urls

So when I load a User, I also want to eagirly load the navigation property Friends. And I want the friend object to eagirly load Clicks and so on.

Using the code I have now I can only do this for 1 level:

public User GetUserById(int userId)
{
  return Get(x => x.Id == userId, includeProperties: "Friends").FirstOrDeafult();
}

Is this possible?

Was it helpful?

Solution

Apparently this repository implementation is just splitting the includeProperties parameter by comma (includeProperties.Split(new char[] { ',' }) and then calls

query = query.Include(includeProperty);

for each element in the result array of the split. For your example you can use a dotted path then:

return Get(x => x.Id == userId, includeProperties: "Friends.Clicks.Urls")
    .FirstOrDefault();

It will load all entities on the path from the root User entity to the last navigation property Urls.

If you had another navigation property in User - say Profile - and you would want to eagerly load that as well, it seems that this syntax is supported then:

return Get(x => x.Id == userId, includeProperties: "Profile,Friends.Clicks.Urls")
    .FirstOrDefault();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top