如何在linq中使用动态列?

时间:2019-01-31 12:22:40

标签: c# linq dynamic datatable

如何使用动态列代替此查询

id = row.Field<int>("id") ,
rec_date = row.Field<string>("rec_date")

var result = from row in dt.AsEnumerable()
             group row by new
             {
                 id = row.Field<int>("id") ,
                 rec_date = row.Field<string>("rec_date")
             } into section1
             select new
             {
                 section1.Key.id,
                 section1.Key.rec_date,
                 children = from l2 in section1
                            select new
                            {
                                tax_rate = l2.Field<string>("tax_rate"),
                                tax_amount = l2.Field<string>("tax_amount")
                            }

             };

var jsonString = JsonConvert.SerializeObject(result);

0 个答案:

没有答案