我遇到的模型類映射覆雜類型的問題錯誤使用的EntityFramework 6.EF6代碼優先/流利的API拋出與複雜類型
(稱爲Assignment
)我有以下Assignment
模型類(僅限相關構件被示出):
public class Assignment
{
private AssignmentDueByInfo _dueIn;
public Assignment() {
_dueIn = new AssignmentDueByInfo(this)
}
public virtual AssignmentSettingInfo DueIn
{
get { return _dueIn; }
protected set { _dueIn = value; }
}
}
其中AssignmentSettingInfo
被定義爲:框架6
public class AssignmentSettingInfo
{
protected AssignmentSettingInfo(Assignment assignment)
{
Assignment = assignment;
}
protected readonly Assignment Assignment;
public virtual int? LessonId { get; protected set; }
public virtual Lesson Lesson { get; protected set; }
}
在實體,我哈已經在數據庫中的以下CodeFirst /流利的API爲Assignment
類表映射:
Property(t => t.DueIn.LessonId).HasColumnName("DueByLessonId");
HasOptional(x => x.DueIn.Lesson)
.WithMany(x => x.AssignmentsDue)
.HasForeignKey(x => x.DueIn.LessonId)
.WillCascadeOnDelete(true);
的映射拋出以下錯誤:
The expression 'x => x.DueIn.Lesson' is not a valid property expression. The expression should represent a property: C#: 't => t.MyProperty'
爲什麼會出現這種情況,它應該如何固定?
我想這是EF限制 - 複雜類型不能包含導航屬性。 –