【发布时间】:2015-01-25 00:57:23
【问题描述】:
我无法弄清楚我在这里做错了什么。我正在使用 asp.net Identity,并创建了一个名为 Person 的新实体。我更新了ApplicationUser 类以引用Person。我想创建一个从Person 到User 的导航属性。但是当我执行更新数据库时,我不断收到一条错误消息
无法确定类型“myapp.Models.ApplicationUser”和“myapp.Models.DataModels.Person”之间关联的主体端。此关联的主体端必须使用关系流式 API 或数据注释显式配置。
public class Person
{
public Guid ID {get; set;}
...
public virtual ApplicationUser user {get; set;}
}
public class ApplicationUser
{
...
public Person person {get; set;}
}
在代码中,我正在执行以下操作
ApplicationUser user = new ApplicationUser {...}
Person person = new Person {....}
user.person = person;
我也想知道是否需要为Person 的虚拟属性设置任何内容,例如person.user = user;
我已尝试通过对虚拟财产执行以下操作来关注此Unable to determine the principal end of an association between the types:
public class Person
{
public Guid ID {get; set;}
...
[ForeignKey("ID")]
public virtual ApplicationUser user {get; set;}
}
谢谢
【问题讨论】:
标签: c# asp.net-mvc entity-framework entity-framework-6