Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>Include</code> is eager loading and it fills navigation properties in real entities without need to project to non entity type - this cannot be achieved with joins. Also <code>Include</code> uses left outer joins whereas your query uses inner joins so you will not get entities which don't have related entity.</p> <p>In EFv1 and EFv4 <code>Include</code> is a method of <code>ObjectQuery</code>. I wrote <a href="https://stackoverflow.com/questions/5376421/ef-including-other-entities-generic-repository-pattern/5376637#5376637">this answer</a> using EFv4.1 which contains extension method for <code>IQueryable&lt;T&gt;</code> as well as <code>Includes</code> with lambda expression. You can <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=b41c728e-9b4f-4331-a1a8-537d16c6acdf&amp;displaylang=en" rel="nofollow noreferrer">try it</a> - it is just another library you will link to your project and you can still use EFv4.</p> <p>The reason to wrap Include in custom method is not introducing dependency to EF in upper layer. If you don't download EFv4.1 you can use this:</p> <pre><code>public static IQueryable&lt;T&gt; IncludeMultiple&lt;T&gt;(this IQueryable&lt;T&gt; query, params string[] includes) where T : class { if (includes != null) { var objectQuery = query as ObjectQuery; if (objectQuery == null) { throw new InvalidOperationException("..."); } objectQuery = includes.Aggregate(objectQuery, (current, include) =&gt; current.Include(include)); } return objectQuery; } </code></pre> <p>The big disadvantage in both approaches (EFv4 and EFv4.1) is casting to ObjectQuery (EFv4.1 do it internally) - this can be serious issue in unit tests where you don't work with real queries.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload