Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This seems a bit confused. You're talking about TPH, but when you say:</p> <blockquote> <p>The way I see it, I should be able to add a reference to a Stored Procedure from within EF (probably using EFExtensions) that has the the TSQL that selects only the fields I need, even using the code generated by EF for the monster UNION/JOIN inside the SP would prevent the SQL being generated every time a call is made - not something I would intend to do, but you get the idea.</p> </blockquote> <p>Well, that's Table per Concrete Class mapping (using a proc rather than a table, but still, the mapping is TPC...). The EF supports TPC, but the designer doesn't. <a href="http://weblogs.asp.net/manavi/archive/2011/01/03/inheritance-mapping-strategies-with-entity-framework-code-first-ctp5-part-3-table-per-concrete-type-tpc-and-choosing-strategy-guidelines.aspx" rel="nofollow">You can do it in code-first if you get the CTP</a>.</p> <p>Your preferred solution of using a proc will cause performance problems if you restrict queries, like this:</p> <pre><code>var q = from c in Context.SomeChild where c.SomeAssociation.Foo == foo select c; </code></pre> <p>The DB optimizer can't see through the proc implementation, so you get a full scan of the results.</p> <p>So before you tell yourself that this will fix your results, double-check that assumption.</p> <p>Note that you can always specify custom SQL for <em>any</em> mapping strategy with <a href="http://msdn.microsoft.com/en-us/library/dd487208.aspx" rel="nofollow">ObjectContext.ExecuteStoreQuery</a>.</p> <p>However, before you do any of this, consider that, as RPM1984 points out, your design seems to overuse inheritance. I like <a href="http://neverindoubtnet.blogspot.com/2009/04/entity-framework-inheritance.html" rel="nofollow">this quote from <em>NHibernate in Action</em></a></p> <blockquote> <p>[A]sk yourself whether it might be better to remodel inheritance as delegation in the object model. Complex inheritance is often best avoided for all sorts of reasons unrelated to persistence or ORM. [Your ORM] acts as a buffer between the object and relational models, but that doesn't mean you can completely ignore persistence concerns when designing your object model.</p> </blockquote>
 

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