4

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 Event contains a child collection of Resource which results in a ResourceEvents table being created even though the ResourceEvents table does not have its own DBSet in DBContext

The DBContext contains

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

This results in the following tables being created

JEvent
Event
JResource
Resource
ResourceEvents

The tables I would like are

JEvent
JResource
JResourceJEvents 

[Update] I have tried the followng in the 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 collection of Resource this solution wont create the JResoureJEvent table.

I have tried the following in the JEvent class

public override IList Resources { get; set; }

However this causes an error

Cannot change return type when overriding property IList

Kirsten
  • 15,730
  • 41
  • 179
  • 318
  • So far the solution seems to be not to inherit from a class but to inherit the relevant interfaces instead. – Kirsten Jul 25 '16 at 23:11

0 Answers0