Skip to content
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

Change Tracker: Enable using backing fields #4461

Closed
rowanmiller opened this issue Feb 2, 2016 · 4 comments
Closed

Change Tracker: Enable using backing fields #4461

rowanmiller opened this issue Feb 2, 2016 · 4 comments
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Milestone

Comments

@rowanmiller
Copy link
Contributor

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.

@patrickmichalina
Copy link

👍
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.

@robinheghan
Copy link

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?

@rowanmiller
Copy link
Contributor Author

@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.

@ajcvickers ajcvickers self-assigned this Jul 8, 2016
@ajcvickers
Copy link
Contributor

Triage: I think we should do this in 1.1

@ajcvickers ajcvickers removed this from the Backlog milestone Jul 8, 2016
@rowanmiller rowanmiller added this to the 1.1.0 milestone Jul 15, 2016
ajcvickers added a commit that referenced this issue Jul 27, 2016
Issue #4461

Previously the materializer would use the backing field, but then when a value needed to be set for fixup, etc, things would fall down. Now we generate delegates everywhere that can use the backing field.

Note that query still prefers the backing field, while fixup prefers the property.

MemberMapper was made a service of the model. Only the minimal done here--we can allow it to be set by convention or fluent API if the need to customize it is requested.

Also fixed #758 - When mapping to backing fields handle cases where field is on base type
ajcvickers added a commit that referenced this issue Jul 27, 2016
Issue #4461

Previously the materializer would use the backing field, but then when a value needed to be set for fixup, etc, things would fall down. Now we generate delegates everywhere that can use the backing field.

Note that query still prefers the backing field, while fixup prefers the property.

MemberMapper was made a service of the model. Only the minimal done here--we can allow it to be set by convention or fluent API if the need to customize it is requested.

Also fixed #758 - When mapping to backing fields handle cases where field is on base type
ajcvickers added a commit that referenced this issue Jul 28, 2016
Issue #4461

Previously the materializer would use the backing field, but then when a value needed to be set for fixup, etc, things would fall down. Now we generate delegates everywhere that can use the backing field.

Note that query still prefers the backing field, while fixup prefers the property.

MemberMapper was made a service of the model. Only the minimal done here--we can allow it to be set by convention or fluent API if the need to customize it is requested.

Also fixed #758 - When mapping to backing fields handle cases where field is on base type
@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jul 28, 2016
@ajcvickers ajcvickers modified the milestones: 1.1.0-preview1, 1.1.0 Oct 15, 2022
@ajcvickers ajcvickers removed their assignment Sep 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Projects
None yet
Development

No branches or pull requests

4 participants