英文:
Entity Framework Map() property alternate in EF Core 6
问题
因为在EF Core中不再支持Map()
属性,所以您需要修改代码以适应EF Core 6。以下是修改后的代码示例:
modelBuilder.Entity<tblStoreGroup>()
.HasMany(e => e.tblUsers)
.WithMany(e => e.tblStoreGroups)
.UsingEntity(j => j.ToTable("tblBridgeUserGroup")
.Property("GroupID", typeof(int))
.Property("username", typeof(string)));
这将帮助您在EF Core 6中实现相同的关联关系。如果您对Entity Framework有任何疑问,请随时提问。
英文:
I am migrating my project from Entity Framework to EF Core 6 but now I am stuck at this point.
modelBuilder.Entity<tblStoreGroup>()
.HasMany(e => e.tblUsers)
.WithMany(e => e.tblStoreGroups)
.Map(m => m.ToTable("tblBridgeUserGroup")
.MapLeftKey("GroupID")
.MapRightKey("username"));
Because the Map()
property is not available in EF Core, can someone please provide a solution for this code?
I am a beginner in Entity Framework.
Thanks in advance
答案1
得分: 1
你可以尝试使用 UsingEntity
:
modelBuilder.Entity<tblStoreGroup>()
.HasMany(p => p.tblUsers)
.WithMany(p => p.tblStoreGroups)
.UsingEntity<Dictionary<string, object>>(
"tblBridgeUserGroup",
j => j
.HasOne<tblUser>()
.WithMany()
.HasForeignKey("username"),
j => j
.HasOne<tblStoreGroup>()
.WithMany()
.HasForeignKey("GroupID"));
请参阅关系配置中的连接部分,查看文档。
英文:
You can try using UsingEntity
:
modelBuilder.Entity<tblStoreGroup>()
.HasMany(p => p.tblUsers)
.WithMany(p => p.tblStoreGroups)
.UsingEntity<Dictionary<string, object>>(
"tblBridgeUserGroup",
j => j
.HasOne<tblUser>()
.WithMany()
.HasForeignKey("username"),
j => j
.HasOne<tblStoreGroup>()
.WithMany()
.HasForeignKey("GroupID"));
See Joining relationships configuration section of the docs.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论