Entity framework 什么';s实体框架等价于NHibernate';s引用(x=>;x.ResidenceCountry).列(";ResidentingCountryID";)?
我有以下代码:Entity framework 什么';s实体框架等价于NHibernate';s引用(x=>;x.ResidenceCountry).列(";ResidentingCountryID";)?,entity-framework,mapping,Entity Framework,Mapping,我有以下代码: class Country { public int CountryId { get; set; } public string CountryName { get; set; } } class Employee { public int EmployeeId { get; set; } public string EmployeeName { get; set; } public int ResidingInCountryId {
class Country
{
public int CountryId { get; set; }
public string CountryName { get; set; }
}
class Employee
{
public int EmployeeId { get; set; }
public string EmployeeName { get; set; }
public int ResidingInCountryId { get; set; }
public virtual Country ResidenceCountry { get; set; }
}
在模型创建时我应该穿什么?因此,我可以通过员工导航国家的国名,我直接从中引用,但我认为这正是您需要的:
以下是如何在Fluent NHibernate中重命名单向一对多关系上的外键:
References(x => x.AudioFormat).Column("AudioFormat");
首先在实体框架代码中,等效代码为:
HasOptional(x => x.AudioFormat)
.WithMany()
.IsIndependent()
.Map(m => m.MapKey(a => a.Id, "AudioFormat"));
你是先用EF4.1和代码吗?是的,我是先用EF4.1和代码。我更新了我的问题。我认为
virtualcountry-ResidenceCountry
需要手动绘制地图。ResidenceCountry
属性的实际支持数据库字段为ResidentingCountry我已经更新了我的答案,希望能有所帮助。我自己还在学习这些东西。EF4.1上不再有独立的方法了。我可以用这个解决我的问题,但是EF的POCO不再是简单的:-)我更喜欢第二种方法(外键在类上,而不是在基元类型上)