如何使用数据库第一种方法命名外键

有没有办法改变entity framework的命名约定?

示例:

我有2张桌子

Planification -------------- creator_id  guest_id  Profile -------------- profile_id  

creator_idguest_id都是profile_id外键

默认情况下,实体会生成这样的规划化类

 public string guest_id { get; set; } public string creator_id { get; set; } public virtual Profile Profile { get; set; } public virtual Profile Profile1 { get; set; } 

我更喜欢像ProfileCreator这样比ProfileProfile1更具体的东西。

有没有办法改变命名约定,因为我感到内疚让它像这样。

在您的edmx中,您可以通过单击属性并更改Name来重命名导航属性。

在此处输入图像描述

请注意,如果删除该表并再次从数据库构建它,则必须在edmx中重命名该表。

如果你对此非常恼火。 绕过它的一种方法是改为使用具有属性的分部类,该属性为默认命名属性提供名称。

 public partial class Planification { public Profile Creator { get{ return this.Profile1; } set{ this.Profile1 = value; } } public Profile Guest { get{ return this.Profile; } set{ this.Profile = value; } } }