LINQ查询复选框列表然后UNION他们的结果 - 错误为NULL [英] LINQ query on checkbox list then UNION their results - error of NULL

查看:125
本文介绍了LINQ查询复选框列表然后UNION他们的结果 - 错误为NULL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了5天时间尝试LINQ复选框chk1,chk2

I have spend 5 days trying on LINQ checkboxes that chk1, chk2

  &NBSP; &NBSP; IQueryable的<简介>临时;

      IQueryable<Profile> temp;

  &NBSP; &NBSP; var temp1 =(chk1 == false)? null:db.Profiles.Where(i =>(i.Point1> 0)||(i.Point1< 0));

      var temp1 = (chk1 == false) ? null : db.Profiles.Where(i => (i.Point1 > 0) || (i.Point1 < 0));

  &NBSP; &NBSP; var temp2 =(chk2 == false)? null:db.Profiles.Where(i =>(i.Point2> 0)||(i.Point2< 0));

      var temp2 = (chk2 == false) ? null : db.Profiles.Where(i => (i.Point2 > 0) || (i.Point2 < 0));

  &NBSP; &NBSP; temp =(temp1.Union(temp2).Distinct()。OrderByDescending(t => t.Lead_ID);

      temp = (temp1.Union(temp2).Distinct().OrderByDescending(t => t.Lead_ID);

但是,返回的一些结果为NULL导致System.ArgumentNullException错误:'值不能为空。

However, some result returned with NULL caused error of System.ArgumentNullException: 'Value cannot be null.

您有任何建议吗?

推荐答案

检查:

var temp1 = chk1?db.Profiles.Where( i => i.Point1!= 0):Enumerable.Empty< Profile>();

var temp2 = chk2?db.Profiles.Where(i => i.Point2!= 0):Enumerable.Empty< Profile>();

 

或者:

temp = db.Profiles.Where(i =>(chk1&& i.Point1!= 0)||( chk2&& i.Point2!= 0))。OrderByDescending(t => t.Lead_ID);


这篇关于LINQ查询复选框列表然后UNION他们的结果 - 错误为NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆