鉴于此代码优先数据模型,我将如何在实体上配置或实现LocalizedName
导航属性,将实例上的属性用于其中一个键,并将上下文中的属性用作另一个键?Product
LocalNameKey
Product
_languageId
public class SampleDataContext : DbContext
{
int _languageId;
public SampleDataContext(int languageId)
{
_languageId = languageId;
}
public DbSet<LocalizedName> LocalNames { get; set; }
public DbSet<Product> Products { get; set; }
public DbSet<Language> Languages { get; set; }
}
public class LocalizedName
{
[Key, Column(Order = 0)]
public Guid Key { get; set; }
[Key, Column(Order = 1)]
public int LanguageId { get; set; }
public string Name { get; set; }
}
public class Language
{
public int Id { get; set; }
public string Name{ get; set; }
}
public class Product
{
public int Id { get; set; }
public string Sku { get; set; }
public Guid LocalNameKey { get; set; }
}