linq2db / linq2db.EntityFrameworkCore

Bring power of Linq To DB to Entity Framework Core projects
MIT License
462 stars 38 forks source link

TPT (table per type) support #289

Closed ds2307 closed 1 year ago

ds2307 commented 1 year ago

Is TPT (table per type) supported?

sdanyliv commented 1 year ago

No, TPT is not supported.

ds2307 commented 1 year ago

Thank you for the quick response. Is there any workaround?

sdanyliv commented 1 year ago

It depends on query which you are tying to execute.

ds2307 commented 1 year ago

Simplified example:

public abstract class A
{
    public Guid Id { get; set; }
    public string Value1 { get; set; }
}

public class B : A
{
    public string Value2 { get; set; }
}

public class C : A
{
    public string Value3 { get; set; }
}

public class ApplicationDbContext : DbContext
{
    public DbSet<A> A => Set<A>();
    public DbSet<B> B => Set<B>();
    public DbSet<C> C => Set<C>();

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    { 
        base.OnModelCreating(modelBuilder);
        modelBuilder.Entity<A>().UseTptMappingStrategy();
    }
}

I want execute dbContext.C.Select( x => new { x.Value3 } ), and I get an exception Inheritance Discriminator is not defined for the 'A' hierarchy.

sdanyliv commented 1 year ago

Not sure that workaround exists. Your query is simple, why do you use linq2db translation then?

ds2307 commented 1 year ago

This is just a basic example. In reality, I use a more complex query. In any case, thanks for the replies. I'll close issue.