How to specify TPT if I inherit a class containing a child collection?

I have the following classes

[Table("JEvent"]
public class JEvent : Event
    {
       public string MoreDetails { get; set; }
    }

Table("JResource")
public class JResource : Resource
{
    public string MoreDetails { get; set; }
}

I know that the Event contains a child Resource collection that leads to the creation of the ResourceEvents table, even if the ResourceEvents table does not have its own DBSet in the DBContext

The DBC text contains

 public DbSet<JEvent> JEvents { get; set; }
 public DbSet<JResource> JResources { get; set; }

This leads to the creation of the following tables

JEvent
Event
JResource
Resource
ResourceEvents

The tables I need

JEvent
JResource
JResourceJEvents 

[Update] I tried followng in DBContext

public class MyDbContext : DbContext {
// ..
protected override void OnModelCreating(DbModelBuilder modelBuilder) {
    base.OnModelCreating(modelBuilder);
    modelBuilder.Ignore<Event>();
    modelBuilder.Ignore<Resource>();
}

}

However, since the Event class contains a child resource set, this solution will not create a JResoureJEvent table.

I tried the following in a JEvent class

public override IList Resources {get; set; }

However this causes an error

Cannot change return type when overriding IList property

+4

Source: https://habr.com/ru/post/1648982/


All Articles