Ivan
Ivan

Reputation: 64207

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

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:

enter image description here

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.

Upvotes: 2

Views: 1689

Answers (1)

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364269

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.

Upvotes: 4

Related Questions