代码优先参考一对多
我有以下两个表:
LOCALIZATION
Id int
Text string
DINER
Id int
Name string
Description string
Name_LocalizationID int
Description_LocationID int
现在我想要这样的 POCO:
public class Diner{
public int Id{get;set;}
public ICollection<Localization> NameLocalization{get;set;}
public ICollection<Localization> DescriptionLocalization{get;set;}
}
public class Localization{
public int Id{get;set;}
public string Text{get;set;}
}
问题是:我们如何使用 EF Fluent API 将 NameLocalization 和 DescriptionLocalization 属性映射到本地化的 Id? 谢谢
I have the following two tables:
LOCALIZATION
Id int
Text string
DINER
Id int
Name string
Description string
Name_LocalizationID int
Description_LocationID int
Now I want my POCO like this:
public class Diner{
public int Id{get;set;}
public ICollection<Localization> NameLocalization{get;set;}
public ICollection<Localization> DescriptionLocalization{get;set;}
}
public class Localization{
public int Id{get;set;}
public string Text{get;set;}
}
Question is: How we can map NameLocalization and DescriptionLocalization property to Localization's Id with EF Fluent API?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
SQL Server 不支持多个级联删除,因此您需要将其中一个关联设置为可选,以便从对象模型派生 SQL Server 架构:
SQL Server does not support multiple cascade deletes, so you need to make one of your associations optional in order to derive a SQL Server schema from your object model:
恐怕我还没有测试过这段代码,但也许是这样的:
I've not tested this code, I'm afraid, but maybe something like: