-
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
Allow mapping of get-only property one-way to database #13316
Comments
@roddharris We discussed this in #7946 and decided that having an empty setter is reasonable for this scenario. For example: public string Fullname
{
get => $"{this.Lastname}, {this.Firstname}";
private set { }
} |
I assume you meant reasonable as a workaround, correct @ajcvickers ? The code looks really hacky and confusing with this in place, so it would be nice if EF just detected the readonly property instead and behaved appropriately. |
To further support @julealgon 's comment, as it stands I need not only a private setter but also a comment explaining why it is needed, and to ignore the warning as my IDE wants me to delete it. I'm in the position of trying to "sell" EF to my company and this makes it harder. |
Hi I have just stumbled upon this. I acknowledge the workaround but it would be nice to have an option in model builder such as public Model
{
public Guid Id { get; set; }
public string Name { get; set; }
public string NormalizedName => Name.ToUpper();
} ...
b.Property(x => x.NormalizedName).IgnoreOnRead();
... |
It would be nice if we could map a get-only property from a POCO to the database so the information gets stored.
An example of this would be a Fullname property getter that computes and returns the full name of a Person. I would like that Fullname stored in the database to make it easier on those who query the database (so they don't have to compute the name). However, because it is computed in my POCO object, I don't need the data mapped back into the object by EF.
The text was updated successfully, but these errors were encountered: