Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DbQuery.Include() method: Is there a strong-typed variant?

This is EF6. I can include .Include() method (no puns intended) in my queries to eager-load information from related tables. However it looks like .Include() method accepts a string parameter only. Is there a way to do it in a strongly-typed way? So for example, instead of writing MyContext.catalog_item.Include("picture"), I could write something like MyDB.catalog_item.Include(i => i.picture) to gain advantages like intellisense and all that.

like image 996
dotNET Avatar asked Apr 17 '14 14:04

dotNET


1 Answers

Yep, there is a strongly typed variant in System.Data.Entity

Usage is

.Include(i => i.Property)

The reference page gives examples on how to include collections and properties on collections as well.

Example:

query.Include(e => e.Level1Collection.Select(l1 => l1.Level2Reference)).
like image 190
mfanto Avatar answered Oct 06 '22 18:10

mfanto