-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Where property on IndexAttribute for Unique constraints #1698
Comments
Hey, This isn't something we'd want to add to the attribute since it is very specific to relational databases. The best place to do this would be to edit the migration once it is scaffolded. We would consider a pull request to add support for this in the migrations index API. ~Rowan |
@rowanmiller I can't seem to find the |
@weitzhandler |
@weitzhandler The |
I still miss the I understand about the Anyway thanks for your help @AndriySvyryd, anyway I haven't managed to find |
How do I define the index order via fluent API? |
@weitzhandler currently not possible. Feel free to open an issue to request it 😄 |
@rowanmiller |
@weitzhandler oh do you mean the order of the columns rather than ASC/DESC? The order of columns is the order that you specify them in the API call to configure the index. |
+1 for IndexAttribute |
1 similar comment
+1 for IndexAttribute |
Yeah. Still hoping to see it back, I think it's not SQL-specific. |
I don't think so. We often make a property as an index like a time field, They are able to be duplicated. Although we can make index and unique in modelbuilding, To implement an IndexAttribute is good for migrate from EF6 or earlier, and makes modeling easily. |
Unique must be related to Index, because UniqueKey must be indexed. |
@divega, @rowanmiller, wouldn't it make sense to keep this issue opened and add a label up for grabs. This looks pretty blunt in a wrong way to close the issue when clearly many consumers are asking for |
@jasonwilliams200OK this issue was specifically about adding the ability to specify a 'WHERE' clause on an index via attributes. Agreed we have got a lot of feedback wanting an [Index] attribute, and we may introduce one based on that feedback. Looks like we don't have an issue tracking it yet, feel free to open one. |
@rowanmiller, should #2675 be reopened? |
Added #4050 to the backlog |
Is this still true, as of RC1?
I can't find the Index method on EntityTypeBuilder. Is it an extension method in another namespace? |
HasIndex is the method you are after - http://docs.efproject.net/en/latest/modeling/relational/indexes.html. |
Is there any way in EF7 to add a unique constraint via migrations? |
Figured it out:
|
Or even better:
|
+1 for IndexAttribute |
3 similar comments
+1 for IndexAttribute |
+1 for IndexAttribute |
+1 for IndexAttribute |
Adding my +1 for IndexAttribute. |
+1 for IndexAttribute |
This issue is closed and will not be considered for planning purposes. Please direct all |
+1 for IndexAttribute |
Is there an update for this? |
Say that I have Attribute like this on my User object/table:
[Index("UNIQ_Nick", IsUnique = true)]
public string Nick { get; set; }
If I don't make Nick required (say I just want emails to register user) constraint will prevent future registrations because in SQL Server IsUnique constraint prevents rows with multiple
This is well described on:
http://stackoverflow.com/questions/767657/how-do-i-create-a-unique-constraint-that-also-allows-nulls
http://stackoverflow.com/questions/24361518/ef-6-1-unique-nullable-index
Do you have any plans to support something like:
[Index("UNIQ_Nick", IsUnique = true, Where="Nick IS NOT NULL")]
??
Would you accept pull request if I implemented this?
The text was updated successfully, but these errors were encountered: