You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Where property on IndexAttribute for Unique constraints #1698
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 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.
@weitzhandlerIndexAttrbiute was never part of DataAnnotations, it was something we had defined in our EF assembly. We may or may not have it in EF7 (there are some issues with the design we had in EF6 so we don't want to carry it over as-is). For the moment, you need to use the Fluent API to add indexes.
I still miss the IndexAttribute anyway. I prefer attributes way over fluent. Especially when the model starts to become complex and the OnModelCreating becomes messy.
BTW, there should be a way to implement an interface in any entity that provides an OnModelCreating called from the context's one, this way, the creation of the entity-specific attributes is kept within the entities.
I understand about the IndexAttribute which is pretty technology-centric, but again, an attribute is just a useless thing on any DTO, so there is no real issue with annotating properties with technology specific attributes, given these attributes are part of any supported framework.
Anyway thanks for your help @AndriySvyryd, anyway I haven't managed to find Order on the fluent API, is it around there?
@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.
Yeah. Still hoping to see it back, I think it's not SQL-specific.
Perhaps the attribute should be renamed to UniqueAttribute, which applies to ANY type of DB, even NoSql, and does resemble the concept of uniqueness rather than an Index which is tied up to specific vendor.
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.
Activity
rowanmiller commentedon Feb 26, 2015
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
weitzhandler commentedon Jul 21, 2015
@rowanmiller I can't seem to find the
IndexAttributeattribute at all.#2675
rowanmiller commentedon Jul 21, 2015
@weitzhandler
IndexAttrbiutewas never part of DataAnnotations, it was something we had defined in our EF assembly. We may or may not have it in EF7 (there are some issues with the design we had in EF6 so we don't want to carry it over as-is). For the moment, you need to use the Fluent API to add indexes.AndriySvyryd commentedon Jul 21, 2015
@weitzhandler The
Indexmethod is toplevel on theEntityTypeBuilder:modelBuilder.Entity<MyEntity>().Index(e => e.prop).Unique()weitzhandler commentedon Jul 23, 2015
@rowanmiller
I still miss the
IndexAttributeanyway. I prefer attributes way over fluent. Especially when the model starts to become complex and theOnModelCreatingbecomes messy.BTW, there should be a way to implement an interface in any entity that provides an
OnModelCreatingcalled from the context's one, this way, the creation of the entity-specific attributes is kept within the entities.I understand about the
IndexAttributewhich is pretty technology-centric, but again, an attribute is just a useless thing on any DTO, so there is no real issue with annotating properties with technology specific attributes, given these attributes are part of any supported framework.Anyway thanks for your help @AndriySvyryd, anyway I haven't managed to find
Orderon the fluent API, is it around there?weitzhandler commentedon Jul 24, 2015
How do I define the index order via fluent API?
rowanmiller commentedon Jul 29, 2015
@weitzhandler currently not possible. Feel free to open an issue to request it 😄
weitzhandler commentedon Jul 30, 2015
@rowanmiller
But when creating a multi-key index, does it take care of the order automatically? By what precedence?
rowanmiller commentedon Jul 30, 2015
@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.
yukozh commentedon Oct 6, 2015
+1 for IndexAttribute
applenele commentedon Oct 25, 2015
+1 for IndexAttribute
weitzhandler commentedon Oct 25, 2015
Yeah. Still hoping to see it back, I think it's not SQL-specific.
Perhaps the attribute should be renamed to
UniqueAttribute, which applies to ANY type of DB, even NoSql, and does resemble the concept of uniqueness rather than anIndexwhich is tied up to specific vendor.yukozh commentedon Oct 25, 2015
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.
yukozh commentedon Oct 25, 2015
Unique must be related to Index, because UniqueKey must be indexed.
7 remaining items
joshcomley commentedon Feb 5, 2016
Figured it out:
joshcomley commentedon Feb 5, 2016
Or even better:
ccpu commentedon Jan 10, 2017
+1 for IndexAttribute
tancevsasa commentedon Apr 21, 2017
+1 for IndexAttribute
Int32Overflow commentedon May 30, 2017
+1 for IndexAttribute
zbrad commentedon Jul 7, 2017
+1 for IndexAttribute
JD-Robbs commentedon Jul 26, 2017
Adding my +1 for IndexAttribute.
OronDF343 commentedon Sep 18, 2017
+1 for IndexAttribute
AndriySvyryd commentedon Oct 2, 2017
This issue is closed and will not be considered for planning purposes. Please direct all
IndexAttributefeedback to #4050davidrevoledo commentedon Oct 31, 2018
+1 for IndexAttribute
kanadaj commentedon Dec 28, 2018
Given that there is a shared package just for relational databases, that seems like a very weak excuse not to do it.
tidusjar commentedon Jun 18, 2019
Is there an update for this?
ajcvickers commentedon Jun 18, 2019
@tidusjar This issue is closed in favor of #4050, which is on the backlog.