更改生成的联接表的名称(多对多)-EF Core 5 [英] Change name of generated Join table ( Many to Many ) - EF Core 5

查看:49
本文介绍了更改生成的联接表的名称(多对多)-EF Core 5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更改EF Core 5创建的联接表的名称?

How to change name of a join table that EF Core 5 Created ?

例如

 public class Food 
    {
        public int FoodId { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
        public string Ingredients { get; set; }
        public string PhotoPath { get; set; }
        public ICollection<Menu> Menus { get; set; }
    }

  public class Menu
    {
        public int MenuId { get; set; }
        [Column(TypeName = "date")]
        public DateTime MenuDate { get; set; }
        public bool IsPublished { get; set; }
        public ICollection<Food> Foods { get; set; }
    }

以及这两个名为FoodMenu的实体的联接表,我想将其更改为其他名称.

and the join table for this 2 entities named FoodMenu, I want to change it to something else..

推荐答案

您可以使用.

由于它是一种关系流利的配置API,因此您首先需要 HasMany + WithMany 对,例如

Since it is a relationship fluent configuration API, you first need HasMany + WithMany pair, e.g.

modelBuilder.Entity<Food>()
    .HasMany(left => left.Menus)
    .WithMany(right => right.Foods)
    .UsingEntity(join => join.ToTable("TheDesiredName"));
   

这篇关于更改生成的联接表的名称(多对多)-EF Core 5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆