I'm having trouble working out what I am doing wrong here. I'm using asp.net Identity and I have created a new entity called Person
. I updated the ApplicationUser
Class to have a reference to the Person
. I wanted to create a navigation property from Person
to User
. But when I execute the Update-Database I keep getting an error message
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;}
}
In the code, I'm doing the following
ApplicationUser user = new ApplicationUser {...}
Person person = new Person {....}
user.person = person;
I'm also wondering whether I need to set anything for the Virtual property of Person
such person.user = user
;
I've tried to follow this Unable to determine the principal end of an association between the types by doing the following on the virtual property:
public class Person
{
public Guid ID {get; set;}
...
[ForeignKey("ID")]
public virtual ApplicationUser user {get; set;}
}
Thanks