-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Can ValueGenerator be applied in add and update situation? #6999
Comments
@JonPSmith Value generators are only invoked when adding a new entity (setting its state to Added) and the property value is the CLR default. We have talked about allowing them to be invoked at other times, but we haven't made any plans to do so. |
Thanks @ajcvickers. All goes to my understanding of EF Core. I may change my example for the book as I'm not sure I'm using Value generators in the way you intended. From looking more at your tests it looks like you designed Value Generators to create keys. It was a good idea while it lasted 😊 |
I would like to ask for this functionality for updates as well. I have an entity that has a Now, I would like to use a value generator to make sure that this normalized column is always calculated properly on top off the current Using a |
Would |
See also discussion here: #19765 |
Added a workaround: #19765 (comment) |
Hi @smitpatel, I tried |
Steps to reproduce
Summary: I am trying to understand the
ValueGenerator
|.HasValueGenerator
feature. To do so Iam trying to create a simple tracking example where I saved the username of the person that created, and the username of person that updated a class.
The issue
It looks like the
ValueGenerator
is only called on an add. Is that correct?I can of course override
SaveChanges\Async
and get at the ChangeTracker to do this (which is what I do in EF6), but I wondered if there was a better way in EF Core.For your laughter here is my code:
Further technical details
EF Core version: "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0-preview1-final"
Operating system: Windows 10
Visual Studio version: VS2015 update 3
Other details about my project setup:
The text was updated successfully, but these errors were encountered: