Open callmeblessed opened 6 years ago
@callmeblessed Try using HasIndex
instead and making the index unique. Alternate keys have additional semantics in EF Core such as not being able to update the property.
I am encountering this issue as well. I can confirm HasIndex()
combined with IsUnique
solved my issue. IMO the docs are misleading. When you google "Unique Constraints" you see that doc first thing. It sounds like you get some unique protection on a column in the database but you dont realize EF wont be able to update it.
Agreed with @VictorioBerra The docs are pretty misleading on this one.
Also, there appears to be no way in EF Core to add a unique constraint without having it also be an alternate key. Sometimes we don't want the extra "alternate key" enforcement that EF adds to the application logic (namely, not being able to change any part of the alternate key), but the dba prefers to have it listed as a unique constraint instead of an index (less likely to accidentally drop an important unique enforcement when evaluating excessive indexes).
I followed this but I cannot update the License Plate because it is a key. How to make it unique but we still able to correct the License Plate later ?
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.