【发布时间】:2016-07-28 14:39:18
【问题描述】:
我正在使用 System.Linq.Dynamic (Install-Package System.Linq.Dynamic),并且我正在尝试将 IndexOf 重载与 StringComparison 一起使用。但是,它的行为就像是在尝试将 StringComparison 运算符应用于 Person 对象。我是否正确编写查询?
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'
对象
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime Birthday { get; set; }
public int Age
{
get
{
DateTime now = DateTime.Today;
int age = now.Year - Birthday.Year;
if (now < Birthday.AddYears(age))
{
age--;
}
return age;
}
}
}
【问题讨论】:
标签: c# linq dynamic dynamic-linq