-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create a 'IsUnique' attribute #23066
Comments
Checkout IndexAttribute which allows you to configure indexes and market them as unique. This feature requires using EF Core 5.0. Current pre-release version on nuget, 5.0-rc2 contains it. |
Thanks @smitpatel that does the job, but isn't it possible to have a simpler attribute per property? Or was there a design decision that said otherwise? |
@BrunoBlanes Is it your intention to create a unique constraint or a unique index in the database, or does it not matter to you which of these is created? |
You got me there, they seem to me to do the same thing, but if I studied properly what I want is a unique constraint, which is to have a single value per cell on a specific column. |
@BrunoBlanes Thanks. So, to ask my question in a slightly different way: the reason you don't want to use |
It is not. |
[Index(nameof(IE), nameof(IM), nameof(CNPJ), IsUnique = true)] This is what I had to do in one case for 3 properties, if I could have set one |
On side note,
Creates a unique index over all 3 properties (composite index). In order to define own separate unique index over each property following should be used
|
Hum, that makes sense, I didn't read enough through the docs to see that, thanks @smitpatel. |
@ajcvickers thanks for considering. |
I would like to not need to type all of this just to set a few columns as unique in the database. This is just for one case, I have an entire set of 20 lines just to set unique constrains in my
OnModelCreating
method.Instead, why not create an
[Unique]
attribute to be used like this:I don't believe this exists, given that I couldn't find any documentation that proved otherwise and also couldn't find any open issues on the matter. Please consider.
The text was updated successfully, but these errors were encountered: