Search This Blog

Thursday 1 August 2019

Dynamic where clause in LINQ

public static IEnumerable<MyObject> WhereQuery(IEnumerable<MyObject> source, string columnName, string propertyValue)
{

// for sorting
//source.OrderBy(m=> m.GetType().GetProperty(columnName).ToString());

     return source.Where(m => { return m.GetType().GetProperty(columnName).GetValue(m, null).ToString().StartsWith(propertyValue); });
}

No comments:

Post a Comment

Popular Posts