System.Linq.Dynamic 错误号 属性 或字段 'StringComparison' 存在于类型 'Person' 中
System.Linq.Dynamic Error No property or field 'StringComparison' exists in type 'Person'
我正在使用 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;
}
}
}
使用枚举可能有问题:How to use Enums with Dynamic Linq?
尝试以下操作:
IEnumerable<Person> dynamicLinqItems = people.Where("(FirstName.IndexOf(@0, @1) >= 0)", "T", StringComparison.OrdinalIgnoreCase);
我正在使用 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;
}
}
}
使用枚举可能有问题:How to use Enums with Dynamic Linq?
尝试以下操作:
IEnumerable<Person> dynamicLinqItems = people.Where("(FirstName.IndexOf(@0, @1) >= 0)", "T", StringComparison.OrdinalIgnoreCase);