开发者

What's the Entity Framework equivalent of NHibernate's References(x => x.ResidenceCountry).Column("ResidingInCountryId")?

开发者 https://www.devze.com 2023-03-04 06:13 出处:网络
I have this code: class Country { public int CountryId { get; set; } public string CountryName { get; set; }

I have this code:

class Country
{
    public int CountryId { get; set; }
    public string CountryName { get; set; }
}


class Emp开发者_如何学Pythonloyee
{
    public int EmployeeId { get; set; }
    public string EmployeeName { get; set; }
    public int ResidingInCountryId { get; set; }
    public virtual Country ResidenceCountry { get; set; }
}

What should I put on OnModelCreating? So I can navigate the Country's CountryName from Employee


I'm quoting directly from this blog posting by Ian Nelson, but I think this is what you need:


Here's how you’d rename a foreign key on a unidirectional one-to-many relationship in Fluent NHibernate:

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

Whilst in Entity Framework code-first, the equivalent is:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号