C#linq选择新语句动态项

时间:2017-09-07 06:48:44

标签: c# linq

//查询实体

  public class ItemClass{
       public string field1{get;set;}
       public string field2{get;set;}
       public string field3{get;set;}
       public string field4{get;set;}
       public string field5{get;set;}
   }

//此变量来自客户端(动态,可能等于ItemClass属性,可能更少)

   var fields = "field1,field2,field3";

// linq查询

var query =from q in items
           select new {
                // can i select field dynamic by variable "fields"
                // as below
                field1=q.field1,
                field2=q.field2,
                field3=q.field3
           };

我想查询数据并通过linq选择项目动态。有谁能够帮我?

0 个答案:

没有答案