AspNetCoreOData icon indicating copy to clipboard operation
AspNetCoreOData copied to clipboard

Get value of property with data member consideration

Open ttruatl opened this issue 3 years ago • 2 comments

Issues

When DataMember is applied in an entity, the entityType.Key() returns a DataMember name and the MemberExpression propertyAccess = Expression.Property(odataItParameter, propertyName); was crashed because the DataMember name couldn't be found in the actual object.

For more details, I setup pageSize=100 in my ODataConfig, and I applied DataMember on the key of an entity

        [DataMember(Name = "Id")]
        [Key]
        public string Name { get; set; }

When I do the $expand on a collection of the entity, the function entityType.Key() in the SelectExpandBinder.cs returns my DataMember name id, then it could not be found at the line Expression.Property(odataItParameter, propertyName) because it's not actual a property name of the object.

Relate issue: #2443

Description

The change is to find the actual property name from the DataMemeber name if the data member name is existing. Otherwise, use the property name from the input.

ttruatl avatar Jul 25 '22 22:07 ttruatl

@xuzhg have you had a chance to look at the related issue #2443?

ttruatl avatar Aug 05 '22 23:08 ttruatl

@xuzhg have you had a chance to look at the related issue #2443?

What do you mean?

My suggestion is to call 'GetClrPropertyName' before calling into this method to get the real property name? Are you using non-Edm scenario?

xuzhg avatar Aug 12 '22 06:08 xuzhg

@ttruatl I have fixed the code as per @xuzhg suggestion. Kindly add tests

KenitoInc avatar Feb 09 '23 05:02 KenitoInc

@microsoft-github-policy-service agree

KenitoInc avatar Jun 30 '23 13:06 KenitoInc

@ttruatl I have added tests. KIndly fix the CLA agreement so that we can resolve this PR

KenitoInc avatar Jun 30 '23 14:06 KenitoInc

Resolved by #980

KenitoInc avatar Jul 05 '23 12:07 KenitoInc