开发者

LINQ: Rewrite an inline query into Linq method style?

How could this be re-written using LINQ methods instead of inline query style?

var cp = from DataRow r in rptDataPkg.Datasets.Item(0).Result.Rows
                where (r.Field<string>("UnitItem") == "PC") &&
                      (r.Field<string>("UnitItem") == "Hs") &&
                      (r.Field<string>("UnitItem") == "U")
                select new CurrProjected 
                { 
                    doAddUp = (r.Field<Decimal>("Fld1") + r.Field<Decimal>("Fld2")) 
                                == r.Field<Decimal>("Fld3")
          开发者_C百科      };


I prefer this syntax to the other solutions, personally.

var cp = rptDataPkg.Datasets.Item(0).Result.Rows
                .Where(r => r.Field("UnitItem") == "PC")
                .Where(r => r.Field("UnitItem") == "Hs")
                .Where(r => r.Field("UnitItem") == "U")
                .Select(r => new CurrProjected
                {
                    doAddUp = (r.Field("Fld1") + r.Field("Fld2"))
                                     == r.Field("Fld3")
                });


Try the following

var cp = rptDataPkg.Datasets.Item(0).Result.Rows
  .Cast<DataRow>()
  .Where(r => (r.Field<string>("UnitItem") == "PC") &&
              (r.Field<string>("UnitItem") == "Hs") &&
              (r.Field<string>("UnitItem") == "U"))
  .Select(r => new CurrProjected 
               { 
                   doAddUp = (r.Field<Decimal>("Fld1") + r.Field<Decimal>("Fld2")) 
                             == r.Field<Decimal>("Fld3")
               });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜