Eric Nielsen Eric Nielsen - 10 months ago 91
C# Question

fetch with Entity Framework

I just copy and post below method from here , this is the definition :

public IList<Post> PostsForCategory(string categorySlug, int pageNo, int pageSize)
var query = _session.Query<Post>()
.Where(p => p.Published && p.Category.UrlSlug.Equals(categorySlug))
.OrderByDescending(p => p.PostedOn)
.Skip(pageNo * pageSize)
.Fetch(p => p.Category);

query.FetchMany(p => p.Tags).ToFuture();

return query.ToFuture().ToList();

But, I'm using Entity framework instead of NHibernate, but EntityFramework doesn't have any definition for
! How can I do that with Entity framework?

Answer Source

You do this through the Include method:

Note, Include is an extension method, so you'll have to add System.Data.Entity to your using statements before it will compile.