简体   繁体   English

实体框架和外键作为字符串

[英]Entity framework and foreign key as string

I have following tables: 我有以下表格:

 Language
    Id (bigint, primary key)
    Name (nvarchar(100))
    Code (nvarchar(2))

  Article
    Id (bigint, primary key)
    LanguageCode (nvarchar(2), foreign key constraint to Language/Code)
    ...

My question: if I generate the model using entity framework 4, it doesn't generate the relation between Article/LanguageCode and Language/Code. 我的问题:如果我使用实体框架4生成模型,它不会生成Article / LanguageCode和Language / Code之间的关系。 Is this an entity framework limitation and should I also add LanguageId to Article table, or am I doing something totally wrong here? 这是一个实体框架的限制吗?我还应该在Language表中添加LanguageId吗?还是我在这里做错了什么?

Thanks! 谢谢!

I think the problem is that Language.Code is not the Primary key of the Language class. 我认为问题在于Language.Code不是Language类的主键。 In your model its allowed to have different Languages with the same Language.Code. 在您的模型中,允许使用相同的Language.Code具有不同的语言。

Another thing. 另一件事。 From Business perspective its much better to have different articles depending on users culture, instead of language. 从业务的角度来看,最好根据用户的文化而不是语言来撰写不同的文章。 Because a Language is not unique for a single culture, and all Business things like CurrencyFormat, DateFormat, Taxes and of course the Law are culture specific. 因为语言不是单一文化的独特之处,所以像CurrencyFormat,DateFormat,Taxes和当然法律这些商业事物都是文化特定的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM