This condition is incorrect, because when the property propName
is missing, it crashes, rather than returning false
:
.Where(x => x.GetType().GetProperty(propName).Name == propName)
If you wanted to say "the dynamic type has the property propName
", a proper condition for it would look like this:
.Where(x => x.GetType().GetProperty(propName) != null)
Note that this is necessary only when some, but not all, subclasses of T
have the desired property propName
. If the property is present in the T
itself, you could get property upfront, and do the rest of the query like this:
var theProp = typeof(T)..GetProperty(propName);
return base.Query<T>().AsEnumerable().Select(x => theProp.GetValue(x, null));