Im trying to enforce unique constraint of a column using fluent configuration for code first. Is there any better way than implementing it in business logic or using something like below
context.ObjectContext.ExecuteStoreCommand("CREATE UNIQUE CONSTRAINT...");
Or I was wondering if it's not possible to implement unique constrain using fluent configurations?
EDIT :
It's confirmed that this is not possible with fluent configurations. But then again I'm wondering what's the best way to do this? And would like to know the reason behind EF not supporting this.
In this example you can see how to define a Unique key attribute and use it in any Entity.
http://code.msdn.microsoft.com/windowsdesktop/CSASPNETUniqueConstraintInE-d357224a
I have this problem occurred before
it can not implement unique constrain using fluent API。
so, the way you used is correct!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With