Linq查询条件里有可空字段比较时报错variable '<>h__TransparentIdentifier2' of type referenced from scope '', but it is not defined
2014-10-16 12:32
537 查看
当我运行下面的linq查询时报了这个错,
1:varresult=(fromsoinsvcContext.new_sales_orderSet2:joinsoiteminsvcContext.new_sales_order_itemSetonso.Idequalssoitem.new_sales_orderid.Id
[/code]
3:joinfpiteminsvcContext.new_fp_itemSetonsoitem.new_modelid.Idequalsfpitem.new_modelid.Id
4:joinfpinsvcContext.new_floor_priceSetonfpitem.new_fp.Idequalsfp.Id
5:whereso.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条件就可以了:
varresult=query.Where(q=>q!=null&&q.Value>0).ToList();
相关文章推荐
- 使用Linq对Hashtable和Dictionary<T,T>查询的效率比较
- SQL查询性能分析之(not in)、(and not)、(<>)、(!=)性能比较
- 区别linq查询中的IEnumerable<T>和IQueryable<T>
- MongoDB小结14 - find【查询条件$lt $lte $gt $gte】
- LINQ 标准的查询操作符 转换 ToList()、ToLookup()、ToEnumerable()、ToDictionary、ToType<T>
- [Elasticsearch2.x] 多字段搜索 (二) - 最佳字段查询及其调优 <译>
- linq 获取实体列表中的某个字段返回ilist<string>
- Jeecg中使用<t: dgCol>标签的自动构造查询条件时出现类型转换错误的解决办法。
- IComparer<T> 接口Linq比较接口
- C#.NET的Linq查询、lambda、委托:Func<>和Action
- LINQ查询中的IEnumerable<T>和IQueryable<T>
- 简单解决Linq多条件组合问题<转>
- 使用Enumerable.OfType<T>扩展方法实现非泛型集合的Linq查询
- 比较不错的asp单表单字段多条件查询
- 如何在<set>查询中加入where条件
- IComparer<T> 接口Linq比较接口
- LINQ查询条件为字段值在数组中
- Hibernate查询任意字段,通过LinkedList<Object[]>取值
- [Elasticsearch2.x] 多字段搜索 (一) - 多个及单个查询字符串 <译>
- ibatis3 关联查询,<association/> coumn添加多列条件