System.Linq.Dynamic Error No property or field 'StringComparison' exists in type 'Person'

c# dynamic dynamic-linq linq

Question

I am using System.Linq.Dynamic (Install-Package System.Linq.Dynamic) and I am trying to use the IndexOf overload with the StringComparison. However, it's acting like it is trying to apply the StringComparison operator to the Person object. Am I writing the query correctly?

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

Error Message

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

Object

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;
        }
    }
}
1
1
9/19/2018 1:30:17 PM

Accepted Answer

It may be an issue with using an enum: How to use Enums with Dynamic Linq?

Try the following:

IEnumerable<Person> dynamicLinqItems = people.Where("(FirstName.IndexOf(@0, @1) >= 0)", "T", StringComparison.OrdinalIgnoreCase);
2
5/23/2017 12:33:14 PM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow