Linq查询条件里有可空字段比较时报错variable '<>h__TransparentIdentifier2' of type referenced from scope '', but it is not defined_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > Linq查询条件里有可空字段比较时报错variable '<>h__TransparentIdentifier2' of type referenced from scope '', but it is not defined

Linq查询条件里有可空字段比较时报错variable '<>h__TransparentIdentifier2' of type referenced from scope '', but it is not defined

 2014/10/16 14:46:18  疯吻IT  程序员俱乐部  我要评论(0)
  • 摘要:当我运行下面的linq查询时报了这个错,1:varresult=(fromsoinsvcContext.new_sales_orderSet2:joinsoiteminsvcContext.new_sales_order_itemSetonso.Idequalssoitem.new_sales_orderid.Id3:joinfpiteminsvcContext.new_fp_itemSetonsoitem.new_modelid.Idequalsfpitem.new_modelid.Id4
  • 标签:
当我运行下面的linq查询时报了这个错,
 
monospace; margin: 0em; width: 100%; background-color: #fbfbfb">  1: var result = (from so in svcContext.new_sales_orderSet
  2: join soitem in svcContext.new_sales_order_itemSet on so.Id equals soitem.new_sales_orderid.Id
  3: join fpitem in svcContext.new_fp_itemSet on soitem.new_modelid.Id equals fpitem.new_modelid.Id
  4: join fp in svcContext.new_floor_priceSet on fpitem.new_fp.Id equals fp.Id
  5: where so.Id == currentEntity.Id
  6: && soitem.new_invoice_price > fpitem.new_floor_price
  7: select (soitem.new_invoice_price - fpitem.new_floor_price) * soitem.new_qty
  8: ).ToList();
 
找了半天原因,才发现是这里的原因:
&& soitem.new_invoice_price > fpitem.new_floor_price
 
因为这二个字段都是Decimal?,有些值是null,比较起来就报错了。
 
把这个条件去掉,然后再加上where条件就可以了:
var result = query.Where(q => q != null && q.Value > 0).ToList();
  • 相关文章
发表评论
用户名: 匿名