本文介绍了更改生成的连接表的名称(多对多)- 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..
推荐答案
您可以使用 UsingEntity
方法重载,例如 .
既然是关系流畅的配置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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!