0
public static PaginationInfo<T> PageList<T, S>(this IQueryable<T> entity, string searchKeyword = "")
    where T : class, new()
    where S : class, new()
{
    //...

    var stringProperties = typeof(S).GetProperties()
                                    .Where(prop => prop.PropertyType == searchKeyword.GetType());
    var query = entity.Where(x => stringProperties.Any(prop => prop.GetValue(x, null) == searchKeyword)).ToList();

    //...
}

当我编写如上所示的代码时,但出现错误:

System.NotSupportedException:无法创建“System.Reflection.PropertyInfo”类型的常量值。此上下文仅支持原始类型或枚举类型。

我应该如何解决这个错误?在此先感谢您的帮助。

4

0 回答 0