It is possible to configure an entity to have a getter-only property that has a backing field. The Query Pipeline will write to this field when creating entity instance. For most cases, the ChangeTracker only needs to read property values, but there are some value propagation cases where we need to set property values (generated properties, FK propagation, etc.). We should enable the ChangeTracker to use the backing field for these cases.
:+1:
This would be a great feature and I currently suspect I am getting bizarre behavior due to the change tracker not being able to use getter-only properties.
Question. Will this work if the backing field is of a different type? I'm using a pattern for validation where I wrap strings and ints in a class that checks for valid input, and allows me to change the format of the input in a simple way. Today this doesn't work so well with EF Core.
Example:
public class Email {
public Email(string email) {
if (!invalidEmail) {
throw new IllegalOperationException("invalid email");
}
this.Email = email;
}
public string ToString() {
return Email.Trim();
}
public string Email { get; set; }
}
public class Model {
string email;
public Email Email {
get { return email == null ? null : new Email(email); }
set { email = value.ToString(); }
}
}
The backing field is here of a different type than the public property, but would this work when this issue has been dealt with?
@Skinney I think they would all need to be the same. I think what you really want is type conversion so that EF can handle a string from the database mapping to your Email type.
Triage: I think we should do this in 1.1
Most helpful comment
Triage: I think we should do this in 1.1