Note that there are some explanatory texts on larger screens.

plurals
  1. PORetrieve only base class from Entity Framework
    text
    copied!<p>If I have three classes in entity framework.</p> <pre><code>class Base {} class Left : Base {} class Right : Base {} </code></pre> <p>and I call <code>DBContext.Bases.ToList();</code></p> <p>This returns all instances of <code>Base</code> fully typed into their associated inherited types, as some people have noticed, the performance of EF on large inheritance structures is not great to say the least. My actual query in my project is 600 lines long, just for returning one entity and takes 2 seconds to generate.</p> <p>They query runs much faster if you tell it which type to return, as it does not have to join across the whole structure. e.g.</p> <pre><code>DBContext.Bases.OfType&lt;Left&gt;.ToList(); or DBContext.Bases.OfType&lt;Right&gt;.ToList(); </code></pre> <p>However I now want to <strong>ONLY</strong> return the base class. Unfortunalty doing</p> <pre><code>DBContext.Bases.OfType&lt;Base&gt;.ToList(); </code></pre> <p>does the same as DBContext.Bases.ToList(); </p> <p>It gets the WHOLE inheritance structure... Is there any way (without making a new type in EF) of <strong>ONLY</strong> returning the class Base when looking through the Base collection?</p> <hr> <p>Sorry I cant log into my actual account...</p> <p>Maybe I didnt make myself clear, I want to bring back all the objects (including Base, Left and Right) but I only want the Base class to be returned, even if in the database they are actual Left and Right classes.</p> <p>OFTYPE was a good suggestion but it filters out all my entities because none are the actual Base type. But I want to return only the Base type values in the Base type object.</p> <p>Any ideas?</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