I'm writing LINQ query that implements a keyword-style search. In other words, a query that returns rows whose Title,Description,Id contains
As follows
public static IQueryable<EmployeeObject> QueryableSQL()
{
IQueryable<EmployeeObject> queryable = EmployeeRepository.GetAllEmployee();
}
public static IList<EmployeeObject> QLike(string txt)
{
IList<employeeObject> _emps = QueryableSQL().Where(x => x.Title == txt).ToList();
return _emps;
}
So far, so good. But this only handles the case where you want to match in my case Title.
Suppose instead, I wanted to search based on the 'DescriptionorIdshould i have to create a new method for Description? or is there a way i can create aTree expression`
public static IQueryable<EmployeeObject> QueryableSQL()
{
IQueryable<MediaObject> queryable = EmployeeRepository.GetAllEmployee();
}
public static IList<EmployeeObject> QLike(Expression<Func<EmployeeObject, bool>> func)
{
return QueryableSQL().Where(func).ToList();
}
You can then call this like:
QLike(t => t.Title == "MyText");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With