什么是实体框架相当于NHibernate的References(x => x.ResidenceCountry).Column(“ResidingInCountryId”)?

时间:2011-05-11 09:27:34

标签: 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 { get; set; }
    public virtual Country ResidenceCountry { get; set; }
}

我应该把什么放在OnModelCreating上?所以我可以从员工导航Country的CountryName

1 个答案:

答案 0 :(得分:1)

我直接从this blog posting Ian Nelson引用,但我认为这就是您所需要的:


以下是如何在Fluent NHibernate中以单向一对多关系重命名外键:

References(x => x.AudioFormat).Column("AudioFormat");

虽然在实体框架代码优先,但等价物是:

HasOptional(x => x.AudioFormat)  
    .WithMany()   
    .IsIndependent()   
    .Map(m => m.MapKey(a => a.Id, "AudioFormat"));