Entity Framework structure table for each type of performance

So, it turns out that I'm the last person who discovered the fundamental gender that exists in the Microsoft Entity Framework when implementing TPT (Table Per Type) inheritance.

Having created a prototype with three subclasses, a base table / class consisting of 20 + columns and child tables consisting of ~ 10 columns, everything worked beautifully, and I continued to work on the rest of the application, proving the concept, Now it's time to add another 20 subtypes and OMG, I just started looking at SQL generated by a simple choice, although I am only interested in accessing the fields of the base class.

This page has an excellent description of the problem.

Has anyone entered production using TPT and EF, are there any workarounds that mean I don’t have to: a) Convert the circuit to TPH (which goes against what I am trying to achieve with my DB design - urrrgghh!)? b) rewrite with another ORM?

As I see this, I should be able to add a reference to the stored procedure from EF (possibly using EFExtensions), which has TSQL, which selects only those fields that I need, even using the code created by EF for the UNION / JOIN monster inside SP will prevent SQL from being generated on every call - not what I would like to do, but you will get an idea.

The killer I found is that when I select a list of entities related to the base table (but the entity that I select is not a subclass table) and I want to filter the base table with pk, and I do .Include("BaseClassTableName")to allow me to filter using x=>x.BaseClass.PK == 1and access other properties, parent SQL generation is also performed here.

I cannot use EF4 as I am limited to .net 2.0 versions with 3.5 SP1 installed.

Does anyone have any experience getting out of this mess?

+5
source share
2 answers

DAL EF4 LLBLGen - .

, :

(LINQ to Entities)

, , ( ), .

Includes() :

static readonly Func<AdventureWorksEntities, int, Subcomponent> subcomponentWithDetailsCompiledQuery = CompiledQuery.Compile<AdventureWorksEntities, int, Subcomponent>(
       (ctx, id) => ctx.Subcomponents
            .Include("SubcomponentType")
            .Include("A.B.C.D")
            .FirstOrDefault(s => s.Id == id));

    public Subcomponent GetSubcomponentWithDetails(int id)
    {
        return subcomponentWithDetailsCompiledQuery.Invoke(ObjectContext, id);
    }
+2

. TPH, :

, EF (, EFExtensions), TSQL, , , , EF UNION/JOIN SP SQL - , , .

, Concrete ( proc, , - TPC...). EF TPC, . , CTP.

proc , , :

var q = from c in Context.SomeChild
        where c.SomeAssociation.Foo == foo
        select c;

proc, .

, , , .

, SQL ObjectContext.ExecuteStoreQuery.

, , , , RPM1984, , , . NHibernate

[A] sk , . , ORM. [ ORM] , , .

+1

All Articles