Skip to content
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

Cannot update alternate key entity framework core 1.0 rc-1 #4914

Closed
ar27111994 opened this issue Mar 28, 2016 · 4 comments
Closed

Cannot update alternate key entity framework core 1.0 rc-1 #4914

ar27111994 opened this issue Mar 28, 2016 · 4 comments

Comments

@ar27111994
Copy link

I'm using entity framework 7 or core 1.0 for my new project. In the products table, ProductName column is set as an alternate key (unique constraint). The problem is that I'm unable to update this column in the database. Here are the details:
stackoverflow question
More details are in the commnts of the stackoverflow post.

@ar27111994 ar27111994 changed the title Cannot update alternate key entity framework core 1.0 Cannot update alternate key entity framework core 1.0 rc-1 Mar 31, 2016
@ar27111994
Copy link
Author

The update query is working fine in SQL server so it really is an Entity Framework issue. @ajcvickers

@rowanmiller
Copy link
Contributor

@ar27111994 EF Core currently does not support changing the value of alternate keys. We do have #4073 tracking removing this restriction though.

BTW it only needs to be an alternate key if you want it to be used as the target key of a relationship. If you just want a unique index, then use the HasIndex() method, rather than AlternateKey(). Unique index values can be changed.

@ar27111994
Copy link
Author

Thank You so much. @rowanmiller

@johnkwaters
Copy link

I have a model where an object has a key that I set manually (SQL Server, not an identity column)
In my code, I fetch one of these objects, then copy it using AutoMapper, and then I set a new value for the key and save it. This gives me an error "The property 'Id' on entity type 'DbProject' is part of a key and so cannot be modified or marked as modified.".
What do I do to basically modify they key value of this new object?

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants