Mar*_*arc 5 c# entity-framework ef-database-first
有没有办法改变实体框架的命名约定?
示例:
我有2张桌子
Planification
--------------
creator_id <fk>
guest_id <fk>
Profile
--------------
profile_id <pk>
Run Code Online (Sandbox Code Playgroud)
creator_id并且guest_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; }
Run Code Online (Sandbox Code Playgroud)
我宁愿比更具体的东西Profile和Profile1喜欢Guest和Creator.
有没有办法改变命名约定,因为我感到内疚让它像这样.
在您的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;
}
}
}
Run Code Online (Sandbox Code Playgroud)