From 46929c2523aeefc4260b20dcc97c665ce44fac64 Mon Sep 17 00:00:00 2001 From: Dean-ZhenYao-Wang <137473325@qq.com> Date: Sat, 23 Jul 2022 13:53:29 +0000 Subject: [PATCH 1/2] Fixed an issue where attributes of the same name cannot be expanded when subclasses inherit and hide attributes of the parent class --- .../Query/Expressions/SelectExpandBinder.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.OData/Query/Expressions/SelectExpandBinder.cs b/src/Microsoft.AspNetCore.OData/Query/Expressions/SelectExpandBinder.cs index 3372fae8d..80f05f40f 100644 --- a/src/Microsoft.AspNetCore.OData/Query/Expressions/SelectExpandBinder.cs +++ b/src/Microsoft.AspNetCore.OData/Query/Expressions/SelectExpandBinder.cs @@ -231,7 +231,11 @@ public virtual Expression CreatePropertyValueExpression(QueryBinderContext conte PropertyInfo propertyInfo = source.Type.GetProperty(propertyName, BindingFlags.DeclaredOnly); if (propertyInfo == null) { - propertyInfo = source.Type.GetProperty(propertyName); + /* + * History of code: + * propertyInfo = source.Type.GetProperty(propertyName); + */ + propertyInfo = source.Type.GetProperties().Where(m => m.Name.Equals(propertyName)).FirstOrDefault(); } Expression propertyValue = Expression.Property(source, propertyInfo); From f9f9dd976babc0a260597839eaae559c26f05724 Mon Sep 17 00:00:00 2001 From: Dean-ZhenYao-Wang <137473325@qq.com> Date: Sat, 6 Aug 2022 10:44:37 +0800 Subject: [PATCH 2/2] This code fixes an issue where 'History of code' was unable to obtain attributes with the same name as the parent class after the subclass hid the parent class member. --- .../Query/Expressions/SelectExpandBinder.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNetCore.OData/Query/Expressions/SelectExpandBinder.cs b/src/Microsoft.AspNetCore.OData/Query/Expressions/SelectExpandBinder.cs index 80f05f40f..50bd6fb88 100644 --- a/src/Microsoft.AspNetCore.OData/Query/Expressions/SelectExpandBinder.cs +++ b/src/Microsoft.AspNetCore.OData/Query/Expressions/SelectExpandBinder.cs @@ -232,9 +232,20 @@ public virtual Expression CreatePropertyValueExpression(QueryBinderContext conte if (propertyInfo == null) { /* - * History of code: - * propertyInfo = source.Type.GetProperty(propertyName); - */ + History of code: + propertyInfo = source.Type.GetProperty(propertyName); + This code fixes an issue where 'History of code' was unable to obtain attributes with the same name as the parent class after the subclass hid the parent class member. + Such as: + 'History of code' cannot get the Key property of the Child. + public class Father + { + public string Key { get; set; } + } + public class Child : Father + { + public new Guid Key { get; set; } + } + */ propertyInfo = source.Type.GetProperties().Where(m => m.Name.Equals(propertyName)).FirstOrDefault(); }