Tag: relational database

在EF Code First中映射自引用实体

在我的数据库中,我有一个表类别,列ID,CategoryName,ParentCategoryId,其中ParentCategoryId对Category.Id有约束。 我首先使用实体​​框架代码,实体看起来像: public class Category { public long Id { get; private set; } public string CategoryName { get; private set; } public long? ParentCategoryId { get; private set; } public Category ParentCategory { get; private set; } public virtual ICollection SubCategories { get; private set; } } 如果我尝试对此运行查询,我会得到exception: The relationship ‘ComplaintModel.FK_Complaint_Category’ was not loaded […]