-
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
Working with backing fields independent of property type #10401
Comments
@glucaci You can map the field directly and not map the property at all: modelBuilder.Entity<Customer>(b =>
{
b.Ignore(e => e.Name);
b.Property("_name");
}); But then you will not be able to use the property directly in a query since EF doesn't know how to handle the "CustomName" class. Beyond that, when #242 is implemented, you can configure the property with a value converter to allow CustomName to be converted to a string when reading and writing to the database. |
@glucaci After discussing in triage we have a follow-up question: what is the reason for including the backing field specifically as a string? Was this just an attempt to get things working with EF, or is there some other reason it is there? |
No other reason @ajcvickers. Only trying to map the model to the DB and in the same time keep the API clean. This with converters sounds nice, there will be some limitations? For example looking on the "CustomName" type or something else that contains composed ValueObjects? |
Currently is not possible to have a different type on the backing field than on the Property.
My ideea was that EF works only with the backing field independent of the property type and use the property name to "fetch" the Column.
Given the next model:
I can achieve this with a weird workaround by creating a shadow property with different name than the model property
It's planed to do it in another way or can be done currently in a simpler way?
Thanks
The text was updated successfully, but these errors were encountered: