Filtering on template list with property name as string

前端 未结 4 1621
灰色年华
灰色年华 2021-01-16 06:26

Hi I have to apply filter on generic class. The sample class is as follows

public class Sample
{
    List sourceList = new List();         


        
4条回答
  •  猫巷女王i
    2021-01-16 06:56

    To query with dynamic expression (as string), you can use Dynamic LINQ by Scott Gu of Microsoft.

    Samples

    It supports following operations
    1. Select
    2. Where
    3. OrderBy
    4. Skip
    5. Take
    6. GroupBy

    All above operations take string as parameter.

    It also has small expression language (to build selectors/predicates/etc) which is very easy to use.

    Example:

    var query =
    db.Customers.
    Where("City = @0 and Orders.Count >= @1", "London", 10).
    OrderBy("CompanyName").
    Select("new(CompanyName as Name, Phone)");  
    

提交回复
热议问题