【发布时间】:2011-05-20 12:44:08
【问题描述】:
您好,我在使用简单的 EF 4.1 代码优先模型时遇到问题。
我有一个双向链接的班级人员和班级调查。数据库模型是正确的,但我总是得到这个错误:
Unable to determine the principal end of an association between the types 'DAL.Models.Survey' and 'DAL.Models.Person'. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations.
类人
[Key]
public Guid Id { get; set; }
[Required]
public string FirstName { get; set; }
[Required]
public string LastName { get; set; }
[Required]
public string Email { get; set; }
public virtual Survey Survey { get; set; }
班级调查
[Key]
public Guid Id { get; set; }
public bool IsFinished { get; set; }
public virtual Person Person { get; set; }
数据上下文:
modelBuilder.Entity<Survey>().HasRequired(s => s.Person).WithOptional().WillCascadeOnDelete(true);
谁能帮忙
【问题讨论】:
标签: c# model-view-controller entity-framework-4 ef-code-first