相关疑难解决方法(0)

Entity Framework Core 多对多更改导航属性名称

我有一个名为“LogBookSystemUsers”的表,我想在 EF Core 5 中设置多对多的功能。我几乎可以正常工作,但问题是我的 ID 列已命名SystemUserIdLogBookId但是当 EF 进行连接时,它会尝试使用SystemUserIDLogBookID。这是我当前的配置代码:

modelBuilder.Entity<SystemUser>()
            .HasMany(x => x.LogBooks)
            .WithMany(x => x.SystemUsers)
            .UsingEntity(x =>
            {
                x.ToTable("LogBookSystemUsers", "LogBooks");
            });
Run Code Online (Sandbox Code Playgroud)

我试过这个:

modelBuilder.Entity<SystemUser>()
            .HasMany(x => x.LogBooks)
            .WithMany(x => x.SystemUsers)
            .UsingEntity<Dictionary<string, object>>("LogBookSystemUsers",
                x => x.HasOne<LogBook>().WithMany().HasForeignKey("LogBookId"),
                x => x.HasOne<SystemUser>().WithMany().HasForeignKey("SystemUserId"),
                x => x.ToTable("LogBookSystemUsers", "LogBooks"));
Run Code Online (Sandbox Code Playgroud)

但这只是添加了两个新列,而不是设置当前列的名称。

这是所有数据库第一。我不想为多对多表使用一个类,因为我在我的项目中一直这样做,我不希望一堆无用的类四处飘散。有任何想法吗?

c# postgresql entity-framework-core entity-framework-core-5

8
推荐指数
1
解决办法
1685
查看次数