В вашем запросе LINQ отсутствует .GetValue(i, null)
.В настоящее время вы сравниваете значение свойства (value
) с PropertyInfo
, описывающим свойство.
Правильный код:
var items = _db.All<T>()
.Where(i => i.GetType().GetProperty(_identityProp)
.GetValue(i, null) == val)
.ToList();
Или, более ориентированный на производительность:
var propertyInfo = item.GetType().GetProperty(_identityProp);
var value = propertyInfo.GetValue(item, null);
var items = _db.All<T>()
.Where(i => propertyInfo.GetValue(i, null) == val)
.ToList();