Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>Why does proxy creation have to be enabled when lazy loading is enabled?</p> </blockquote> <p>Because lazy loading with POCOs relies on proxy creation. Without proxies lazy loading doesn't work. Therefore the combination <code>ProxyCreationEnabled = false</code> and <code>LazyLoadingEnabled = true</code> makes no sense. The reverse combination makes sense, in case you want to work with change tracking proxies but don't want to use lazy loading.</p> <blockquote> <p>If I want to set lazyloading = false, can I cast my IEnumerable in Service layer to ObjectQuery in order to use .Include() there?</p> </blockquote> <p>It depends on what your <code>IEnumerable&lt;T&gt;</code> really <em>is</em>. If it's the result of a <code>ToList()</code> then no (because <code>List&lt;T&gt;</code> is an implementation of <code>IEnumerable&lt;T&gt;</code> but not of <code>IQueryable&lt;T&gt;</code>.). If you just return an <code>IQueryable&lt;T&gt;</code> as <code>IEnumerable&lt;T&gt;</code> you probably can cast to <code>IQueryable&lt;T&gt;</code>. (In EF 4.3 you would use <code>IQueryable&lt;T&gt;</code> or <code>DbQuery&lt;T&gt;</code> rather than <code>ObjectQuery&lt;T&gt;</code>.)</p> <p>But imho the need for such a cast indicates that something is wrong in your architecture. Using <code>Include</code> is a modification of a query. If your service layer is allowed to modify queries your repository should return <code>IQueryable&lt;T&gt;</code> - this type is made for building and modifying queries.</p> <p>If your repository is not supposed to return <code>IQueryable&lt;T&gt;</code> you must pass in an expression or a specification into the repository methods which is used to add an <code>Include</code> to your query - inside of the repository method, not in the service layer.</p>
 

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