Does Entity Framework 5 support unique constraints?

aknuds1 picture aknuds1 · Aug 5, 2012 · Viewed 14.3k times · Source

Wondering if Entity Framework 5 supports unique constraints on entity properties? If so, how can I specify that a property should be unique?

Answer

Slauma picture Slauma · Aug 5, 2012

No, it doesn't. There were plans in the past to include a unique constraint feature in EF 5.0:

http://blogs.msdn.com/b/efdesign/archive/2011/03/09/unique-constraints-in-the-entity-framework.aspx

But you can see that there is an update on top of the post:

Update: this feature has been postponed and will not be included in Entity Framework 5.

You can vote on the feature to raise possibly the priority it gets implemented with...

http://data.uservoice.com/forums/72025-entity-framework-feature-suggestions/suggestions/1050579-unique-constraint-i-e-candidate-key-support

...because apparently it isn't even on the roadmap for EF 6.0 at the moment:

http://entityframework.codeplex.com/wikipage?title=Roadmap