Search code examples
c#entity-frameworklinq

Issues with execute dynamic query in Entity Framework Core 6.0.8


I have used EF 6.0.8 in my project

Here, you can see an example of my code

var searchCriteria = CreateSearchString<T>(model);
if (!string.IsNullOrEmpty(searchCriteria))
{
    result = !string.IsNullOrEmpty(searchCriteria)
        ? enumerable.AsQueryable().Where(searchCriteria, model.Search.Value.ToLower())
        : enumerable.AsQueryable();
}

"( it.Parent1FirstName != null && it.Parent1FirstName.ToString().ToLower().Contains("Parent1"))"

Ui request model will send a dynamic query object (column properties and value) to filter data based on they need in grid view. See below the image.

enter image description here

A query was applied to my enumerable data source, but it was not filtering data. See below the image.

enter image description here

DATABASE SOURCE

enter image description here

Resolved: It was my fault. The answer is in the comment.


Solution

  • Resolved, It was my bad.

    I was comparing .toLower() case only for value not for properties

    It's working fine now.