0

I've been looking for a way to set a field unique , but i' am surprised i can't find anything like annotation on the field. In most of the resource online one have to write SQL in an initializer. i was even hoping i could find something like

modelBuilder.Entity<Profile>().HasKey(p => p.RollNumber);

in which HasKey could be HasUnique or even HasUniqueKey

Is it that am not searching with the proper keyword or that annotation feature is simply not available (to my surprise ).

Community
  • 1
  • 1
black sensei
  • 6,528
  • 22
  • 109
  • 188

1 Answers1

1

In addition to the comments:

There was a promising post on some design considerations regarding unique constraint support almost a year ago at the Entity Framework Design design blog. However, there is no mention of it in EF 5.0.0 beta1 pre-release.

I can not find any later reference to it on the EF blogs or on the pre-release forum, neither is there a (public) roadmap so it is hard to tell when or whether this feature will be released.

So, not really an answer to your question, because there is no "how to" yet.

Gert Arnold
  • 105,341
  • 31
  • 202
  • 291