相关疑难解决方法(0)

在实体框架中使用Fluent API创建多对多关系

使用实体框架的API,我不断遇到以下两种方式来映射多对多关系?我从未使用过第二个选项...有什么区别?

选项1:

modelBuilder.Entity<Student>()
    .HasMany( p => p.Lessons)
    .WithMany();
Run Code Online (Sandbox Code Playgroud)

选项2:

modelBuilder.Entity<Student>()
.HasMany(p => p.Lessons)
.WithMany() 
.Map(m =>
{
    m.MapLeftKey("Id");
    m.MapRightKey("Id");
    m.ToTable("StudentAndLessons");
});
Run Code Online (Sandbox Code Playgroud)

这到底是什么MapLeftKeyMapRightKey做什么?您何时使用它并获得什么好处?

c# entity-framework fluent-interface

2
推荐指数
1
解决办法
1267
查看次数

标签 统计

c# ×1

entity-framework ×1

fluent-interface ×1