有没有办法使用Entity Framework更改命名约定?
范例:
我有2张桌子
Planification
--------------
creator_id <fk>
guest_id <fk>
Profile
--------------
profile_id <pk>
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; }
我更喜欢比Profile
andProfile1
喜欢Guest
和更具体的东西Creator
。
有没有办法更改命名约定,因为让我这样感到非常内gui。
在edmx中,您可以通过单击属性并更改来重命名nav属性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;
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句