Create unique attribute beyond Primary Key in code-first

Asked

Viewed 288 times

4

I’m creating a table of Logradouro where the countryside CEP is not the primary key, but should be unique.
How do I do it using code-first in the Entity 6.0?

To create primary key I use the method HasKey:

ToTable("Logradouros").HasKey(x => x.LogradouroId);

I saw that in this method it is possible to use more than one field creating composite key. If the CEP must be unique and indexed it must be table key too?

1 answer

3


  • According to the links the first solution only works from the Entity 6.1 and the second relates to Entity 6.2, I need one that works on Entity 6.0 (I edited my question to specify this)...

  • but what problem 6.1 and 6.0 have very similar Ipps you can do the simple update by nuget

  • I updated Entities and the first solution worked well, thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.