EF -- Unable to determine the principal end of an association between the types

asp.net-mvc c# entity-framework entity-framework-6

Question

I'm having a hard time figuring out what I'm doing incorrectly. Asp.net Identity is what I'm using, and I made an entity calledPerson . I changed theApplicationUser class to include a mention of thePerson . A navigation property was something I wanted to make.Person to User . However, I continue to receive errors when I run the Update-Database command.

Unable to determine the principal end of an association between the types 'myapp.Models.ApplicationUser' and 'myapp.Models.DataModels.Person'. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations.

public class Person 
{
    public Guid ID {get; set;}
    ...
    public virtual ApplicationUser user {get; set;}
}

public class ApplicationUser
{
    ...
    public Person person {get; set;}
}

I'm performing the following in the code.

ApplicationUser user = new ApplicationUser {...} 

Person person = new Person {....} 
user.person = person;

Additionally, I'm unsure if I need to make any changes to the Virtual Property ofPerson such person.user = user ;

I've made an effort to adhere to this by doing the following actions on the virtual property:

public class Person 
{
    public Guid ID {get; set;}
    ...
    [ForeignKey("ID")]        
    public virtual ApplicationUser user {get; set;}
}

Thanks

1
1
5/23/2017 12:31:59 PM

Popular Answer

In 1:1 Relation must have two ends that are principal and dependent. The end that will be inserted and can be are independent of the dependent one is the -16-zzz end. The end that must be added following the principal is the one that has an exotic key since it principal. Here, you must include.[Required] principal attribute to one, and removal[ForeignKey("ID")] from the prototype.

Additionally, you concatenated sluggish loading (Virtual quickly loading characteristics and attribute) in your models.

4
1/25/2015 1:19:19 AM


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