我的问题是我需要在一个泛型类中查询一个属性的值。该属性已被标记为属性。
请参阅以下代码:
var rowKeyProperty = EFUtil.GetClassPropertyForRowKey<T>();
var tenantKeyProperty = EFUtil.GetClassPropertyForTenantKey<T>();
var queryResult =
objContext.CreateObjectSet<T>().Single(l => (((int) tenantKeyProperty.GetValue(l, null)) == tenantKey) &&
(((int)rowKeyProperty.GetValue(l, null)) == KeyValue));
rowKeyProperty和tenantKeyProperty的类型为System.Reflection.PropertyInfo。
我理解为什么会出现错误。当linq查询转换为SQL时,它无法理解property.GetValue。
然而,我完全不知道如何解决这个问题。有人有任何想法如何实现吗?谢谢。