我有一个现有的数据库我想用和Entity Framework Code First。基于这个文章( blogs.msdn/b/adonet/archive/2011/01/10/ef-feature-ctp5-pluggable-conventions.aspx?wa=wsignin1.0 ) I我正在尝试更改默认约定。我已成功更改它以使用单数表名称,但现在想要调整导航属性的行为方式。 看下面的例子,我想能够在数据库中有一个名为'HomeAddressId'的字段这是Person表中的外键到Address表中的主键。如果我添加名为HomeAddressId的主要属性,它可以工作,但我希望能够删除它。删除后,它将采用HomeAddressAddressID的名称。 如何更改约定以使用PropertyName +" ID"? How can I change the conventions to use the PropertyName + "ID"? 感谢您的帮助...... Thank you for your help... public class 人员< { public int PersonId { get ; set ; } public string FirstName { get ; set ; } public string LastName { get ; set ; } public 虚拟 地址 HomeAddress { get ; set ; } } public
class
Person
{
public
int
PersonId { get;
set;
}
public
string
FirstName { get;
set;
}
public
string
LastName { get;
set;
}
public
virtual
Address
HomeAddress { get;
set;
}
} public class 地址 { public int AddressId { get ; set ;} public string 地址1 { get ; set ; } public string City { get ; set ; } public string 状态{ get ; set ; } public string Zip { get ; set ; } } public
class
Address
{
public
int
AddressId { get;
set;}
public
string
Address1 { get;
set;
}
public
string
City { get;
set;
}
public
string
State { get;
set;
}
public
string
Zip { get;
set;
}
} Hi William,
Hi William,
这在CTP5中预览的约定功能中是不可能的(关系的配置仍然是内部的。)而不是使用约定,你可以编写一些代码来反映您的类型,查找引用属性并使用反射来调用Fluent API。由于Fluent API中的所有通用方法,它将是混乱的代码,但它应该是可能的。 This isn't possible in the convention functionality that was previewed in CTP5 (configuration of relationships was still internal). Rather than using conventions, you could write some code to reflect over your types, look for reference properties and use
reflection to call the Fluent API. It will be messy code because of all the generic methods in the Fluent API, but it should be possible. ~Rowan
更多推荐
在将navagation属性用于复杂类型时,使用可插入约定来更改外键的默认属性名称。
发布评论