Home > Net >  Dynamic Linq query was introduced into the column
Dynamic Linq query was introduced into the column

Time:04-30

There is a List:

The column name: id productName Num
Contents: 1 book1 sn25124
2 book2 sn554124


Now want to is controlled by the client, just select the id/productName after two fields, how to use linq query the records into such as follows:

Id productName
1 book1
2 book2


Var listOther=List. Select (x=& gt; ????? )


thank you

CodePudding user response:

Since to dynamically allocated key, use Dictionary

 var _keys=new List {" id ", "productName}"; 

Dictionary Dic=new Dictionary (a);
_keys. ForEach (k=& gt;
{
Dic [k]=x.G etType () GetProperty (k). The GetValue (x);
});
Return dic.

CodePudding user response:

Is there a written linq?
  • Related