Eric Nielsen Eric Nielsen - 24 days ago 11
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)
.Take(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
Fetch
or
FetchMany
! How can I do that with Entity framework?

Answer

You do this through the Include method: http://msdn.microsoft.com/en-us/data/jj574232.aspx

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

Comments