EF6 Foreign Key Issue

entity-framework entity-framework-6

Question

I have my models here.

public class Driver
{
    public int Id { get; set; }
    public String Name { get; set; }
    public int VehicleId { get; set; }
    public virtual Vehicle Vehicle  { get; set; }
}

public class Vehicle
{  
    public int Id { get; set; }
    public String Name { get; set; }

    public virtual Driver Driver { get; set; }

    public int VehicleGroupId { get; set; }
    public virtual VehicleGroup Vehicles { get; set; }
}

When updating the database, I receive the following error:

A relationship between the types "AppName.Models.Vehicle" and "AppName.Models.Driver" could not be determined as its primary end. The relationship fluent API or data annotations must be used to explicitly configure the principal end of this association.

I want to use data annotations to resolve the problem. I've tried adding a foreign key attribute to the car model's Driver Navigation property. but with no luck. I sincerely appreciate any assistance.

1
1
1/18/2014 12:04:14 PM

Accepted Answer

ZZZ_tmp
0
1/18/2014 12:01:47 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