-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Enable configuring default/computed property values with a lambda expression #11001
Comments
Also consider doing it for all relevant metadata APIs at the same time (default value, computed value, check constraint...). |
I wanted to post here and say that I could really use this feature as well. In our scenario, we pull data from JSON APIs and cache the responses in a SQLite table. When we do, we cache the raw JSON in a column but also store important properties in their own columns. It would be nice to not have to manually map the important properties from the JSON object to the table on add and update and instead be able to let EFCore handle this for us. |
Note that this issue doesn't remove the need to "manually" map your properties; it only allows you to do it via a LINQ expression instead of via SQL. |
Yes. You are correct. I'd like to do the mapping once when I configure the context and have it automatically re-apply whenever the source data changes. |
So again - you're already able to do that by configuring a computed column as usual, and specifying raw SQL in the computed column definition which fetches data from column (e.g. with the |
I am hopeful that when this gets implemented, I will be able to express computed properties as provider independent C# expressions as opposed to provider-dependent SQL scripts. |
Hey, just want to share that for a few weeks I've working on auto-updated "computed properties" in EF Core: https://github.com/lucaslorentz/computed-expression. Unofficial project! It doesn't solve the issue reported by @divega, but seems a good fit for @TonyValenti use case |
Hi @lucaslorentz - Does this allow calling custom functions and such in the computed property expression? |
The main purpose of this feature is to simplify implementing the write side of the multi-tenant scenarios using a declarative approach in the model. Currently you do this writing some imperative code in an override of SaveChanges.
This could be a new overload of
HasDefaultValue
that allows passing aExpression<Func<T>>
(or even aFunc<TDbContext, T>
if we are ok with drifting from the pattern used by query filters).This would enable obtaining the value from the actual
DbContext
instance used at SaveChanges time.Example:
This should save you from having to write this kind of code:
cc @anpete
The text was updated successfully, but these errors were encountered: