Skip to content

Test that materialization, etc.handles entities that use C# 6 features #1311

Closed as not planned

Description

@ajcvickers

In particular read-only auto properties.

Activity

  1. added this to the 7.0.0 milestone on Jan 5, 2015
  2. rowanmiller commented on Jan 9, 2015

    @rowanmiller
    Contributor

    Please discuss with @ajcvickers
    Also summarize what you tested (and findings) at design meeting

  3. smitpatel commented on Jan 21, 2015

    @smitpatel
    Contributor

    I tried adding test in EntityMaterializerSourceTest which contains entity with read only auto properties. It throws following exception

    System.InvalidOperationException : No backing field could be discovered for property 'Microsoft.Data.Entity.Tests.Metadata.EntityMaterializerSourceTest+SomeEntityReadOnly.Foo' and the property does not have a setter. Either use a backing field name that can be matched by convention, annotate the property with a backing field, or define a property setter.
    
  4. divega commented on Jan 22, 2015

    @divega
    Contributor

    @smitpatel I think for that particular case it is expected. We would probably need materialization to support matching constructor parameters to be able to work with those entities. It may be a good idea to file a bug for that and then we can discuss the priority.

  5. smitpatel commented on Jan 24, 2015

    @smitpatel
    Contributor

    It is possible to find backing field of read-only auto property through reflection.
    The backing field is constructed using pattern k__BackingField

    Following method gives access to backing field.

    private string _getBackingFieldName(string propertyName)
    {
        return string.Format("<{0}>k__BackingField", propertyName);
    }
    
    private FieldInfo _getBackingField(object obj, string propertyName)
    {
        return obj.GetType().GetField(_getBackingFieldName(propertyName), BindingFlags.Instance | BindingFlags.NonPublic);
    }

    Then we can use this code to set the value

    var field = _getBackingField(myObjectToChange, "PropertyName");
    field.SetValue(myObjectToChange, NewValue);
  6. smitpatel commented on Jan 24, 2015

    @smitpatel
    Contributor

    Marking for re-triage to decide what to do next for this.

  7. bricelam commented on Jan 24, 2015

    @bricelam
    Contributor

    Given that the semantics of getter-only auto properties are the same as readonly fields, should we even be trying to set these fields in the first place?

  8. ilmax commented on Jan 24, 2015

    @ilmax
    Contributor

    +1 for materialization via constructor. This is a good feature and lot of people would like to have this.

  9. rowanmiller commented on Feb 2, 2015

    @rowanmiller
    Contributor

    Discussed in triage and agreed that we should not include a getter-only property in the model by convention. Logged these two issues as a result of the discussion:

  10. removed their assignment
    on Mar 21, 2015
  11. removed this from the 1.0.0 milestone on May 11, 2016
  12. divega commented on May 11, 2016

    @divega
    Contributor

    Clearing up milestone so that we can review this in triage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions