System.Linq.Dynamic错误类型'Person'中不存在属性或字段'StringComparison'

时间:2016-04-07 15:33:26

标签: c# linq dynamic dynamic-linq

我正在使用System.Linq.Dynamic(app.directive('myDirective', function($scope){ return { restrict: 'E', template: 'I want to print the attribute value', controller: function($scope){ // I also want to access the attribute value here. } }; }); ),我正在尝试将StringOf重载与StringComparison一起使用。但是,它正在尝试将StringComparison运算符应用于Person对象。我正确地写了查询吗?

Install-Package System.Linq.Dynamic

错误消息

try
{
     IEnumerable<Person> dynamicLinqItems = people.Where("(FirstName.IndexOf(@0, StringComparison.OrdinalIgnoreCase) >= 0)", "T");
}
catch (Exception exception)
{
    Console.WriteLine(exception);
}

对象

No property or field 'StringComparison' exists in type 'Person'

1 个答案:

答案 0 :(得分:2)

使用枚举可能会出现问题:How to use Enums with Dynamic Linq?

尝试以下方法:

IEnumerable<Person> dynamicLinqItems = people.Where("(FirstName.IndexOf(@0, @1) >= 0)", "T", StringComparison.OrdinalIgnoreCase);