【发布时间】:2018-12-06 12:42:58
【问题描述】:
在 Entity Framework 6 中使用代码优先。
我有这个实体:
public class LineSection
{
public int Id { get; set; }
public List<LineSection> Next { get; set; }
public List<LineSection> Previous { get; set; }
}
我添加一个迁移,只是为了看看数据库将如何:
CreateTable(
"dbo.LineSectionLineSections",
c => new
{
LineSection_Id = c.Int(nullable: false),
LineSection_Id1 = c.Int(nullable: false),
})
.PrimaryKey(t => new { t.LineSection_Id, t.LineSection_Id1 })
.ForeignKey("dbo.LineSections", t => t.LineSection_Id)
.ForeignKey("dbo.LineSections", t => t.LineSection_Id1)
.Index(t => t.LineSection_Id)
.Index(t => t.LineSection_Id1);
我不喜欢默认命名。我可以更改表名(LineSectionLineSections)和两个外键(LineSection_Id 和 LineSection_Id1)。使用模型构建器、数据属性或其他方式?
【问题讨论】:
-
MapLeftKey,MapRightKey。例子很多,比如stackoverflow.com/questions/16490334/… -
请为我的案例展示一个完整的例子。据我所知,您的示例不适合我的情况,因为实体中只有列表,而不是两个。
-
没关系,但你去吧。
标签: entity-framework entity-framework-6 ef-code-first