我的MVC LINQ代码返回AND AND AND ::我想要OR OR OR

时间:2014-07-24 23:14:44

标签: c# sql linq

ActionResult末尾的代码根据选中的复选框返回行。看起来它工作直到我意识到是否检查了多个复选框,然后只返回具有所有criteria = true的行(因此人类SQL将读取:WHERE 1 = 1 AND(AND AND AND)。

我正试图绕过一种方法来返回已经搜索过字符串的行,并且检查了任何一个复选框条件。 (人类SQL将是WHERE(1 = 1)AND(OR OR))。

 public ActionResult Index(string searchString, int? searchID, string LastN, bool? bolDWP, bool? bolDEQ, bool? bolOnsiteInstall, bool? bolOnsiteOandM)
    {

   if (!String.IsNullOrEmpty(searchString))
    {

     courses = courses.Where(s => s.CourseTitle.Contains(searchString));       

       if (bolDWP == true)

        {
            courses = courses.Where(s => s.CEUDWP != null);
        }


        if (bolDEQ == true)

        {
            courses = courses.Where(s => s.CEUDEQ != null);
        }

        if (bolOnsiteInstall == true)

        {

            courses = courses.Where(s => s.CEUonsiteInstall != null);

        }



        if (bolOnsiteOandM == true)

        {
            courses = courses.Where(s => s.CEUonsiteOandM != null);
        }

  }

        return View(courses.OrderByDescending(s => s.OESACID));

 }

0 个答案:

没有答案