Duplicate ForeignKey when using inheritance

c# entity-framework entity-framework-6 relational-database

Question

In order to produce the database model using the EntityFramework 6 code-first method, I developed the following classes:

public class Vehicle 
{
    public long Id { get; set; }

    public long ResponsiblePersonId { get; set; }
}

public class Car: Vehicle {

    public int HorsePower { get; set; }

}

public class Bike: Vehicle {

    public int FrameSize { get; set; }

}

public class Organisation
{
    public Organisation()
    {
        Cars = new List<Car>();
        Bikes = new List<Bikes>();
    }

    public long Id { get; set; }


    public List<Car> Cars { get; set; }

    public List<Bike> Bikes { get; set; }
}

This has so far seemed appropriate to me. But regrettably, the resultant table appears as follows:

Id | ResponsiblePersonId | HorsePower | FrameSize | Discriminator | Organisation_Id | Organisation_Id1

The Organisation ForeignKey is produced twice; why? This table was supposed to contain only one field for the Organization Id.

Thanks

1
3
7/14/2017 4:08:01 PM

Accepted Answer

ZZZ_tmp
3
7/16/2017 3:51:25 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow