Home > Net >  Linq to dynamic query specified field
Linq to dynamic query specified field

Time:05-20

There is a List of data, name: lstResult

Now want to according to the incoming parameters A, B value, query out the records of column lstResult

Namely, when only A statement for the var queryable=the from A lstResult in the select new {Column1=a.A}

When there is A, B, statements for var queryable=the from A lstResult in select new {column1=a.A, column2=a.}

When only B, statements for var queryable=the from a lstResult in select new {column1=a.}

The above three kinds of situation, how the whole together?? thank you

CodePudding user response:

With the lambda method and then write their own an extension method to select

Extension methods according to your condition judgment, and then select

CodePudding user response:

The return type is not sure, you can directly use the dynamic type
  • Related