AspNetCoreOData
AspNetCoreOData copied to clipboard
Get value of property with data member consideration
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.
@xuzhg have you had a chance to look at the related issue #2443?
@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?
@ttruatl I have fixed the code as per @xuzhg suggestion. Kindly add tests
@microsoft-github-policy-service agree
@ttruatl I have added tests. KIndly fix the CLA agreement so that we can resolve this PR
Resolved by #980