开发者

How to use a foreign key as a part of a composite primary key in Entity Framework?

开发者 https://www.devze.com 2023-03-09 15:01 出处:网络
I\'ve got an entity which is identified by no own id but an unique combination of properties, each of which is a foreign key.

I've got an entity which is identified by no own id but an unique combination of properties, each of which is a foreign key.

But Entity Framework designer does not seem to allow to make a foreign key (a "navigation property") 开发者_开发知识库a part of a primary key. Am I misunderstanding something or is it just unsupported?

Example:

How to use a foreign key as a part of a composite primary key in Entity Framework?

here an instrument is designated by a very short symbolic identifier (name), which doesn't seem to be wise to be replaced by a numeric code.


Navigation properties cannot be part of primary key. Composite primary key (entity key) can consists only from scalar properties -> only foreign properties related to these navigation properties can be part of FK - here is the example of the model which uses such relation.

0

精彩评论

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