【问题标题】:How do you name a many-to-many relationship table using Fluent Api?如何使用 Fluent Api 命名多对多关系表?
【发布时间】:2021-06-23 15:56:18
【问题描述】:

我创建了 多对多 关系,而表的名称(具有两个记录/对象的 Id 的表)对我没有吸引力。

那么如何使用 Fluent Api 命名该表?在一张普通的桌子上我会使用ToTable("Name"),但是我该如何在这张非典型桌子上做同样的事情呢?

【问题讨论】:

    标签: entity-framework ef-code-first many-to-many ef-fluent-api tablename


    【解决方案1】:

    看起来你仍然使用ToTable() 方法和UsingEntity() fluent api:

    modelBuilder
        .Entity<Post>()
        .HasMany(p => p.Tags)
        .WithMany(p => p.Posts)
        .UsingEntity(j => j.ToTable("PostTags"));
    

    【讨论】:

    • 它声称没有 UsingEntity 这样的东西。
    • 这个例子直接取自documentation。查看并检查您的 EF Core 版本。
    • 好的,我去看看。
    猜你喜欢
    • 2014-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-22
    • 1970-01-01
    • 2021-10-24
    • 2011-03-16
    • 2023-03-31
    相关资源
    最近更新 更多