我有一个EF代码第一个数据库。
我有几个实体:
其中Orders引用Customer
IE
public class Orders
{
public Guid Id {get; set;}
public Customer Customer {get; set}
//snip...
}
这生成了一个带有两个表的数据库
订单中有一个字段 Customer_id 我需要将此字段重命名为 CustomerId 。
我知道我可以映射它,但我希望这是一个惯例。
我看过这个页面http://msdn.microsoft.com/en-us/library/system.data.entity.modelconfiguration.conventions%28v=vs.103%29.aspx,但我不清楚这些约定的含义。
我正在使用SqlServer 2008。
答案 0 :(得分:3)
Customer_id由EF惯例生成。
您必须声明一个外键并使用数据注释来关联它。
using System.ComponentModel.DataAnnotations;
public class Orders
{
public Guid Id {get; set;}
public Guid CustomerId {get; set;}
[ForeignKey("CustomerId")]
public Customer Customer {get; set}
//snip...
}