I can build the WHERE clause with a varying number of "AND"s in a string in PHP and then concatenate it to the end of my SELECT statement before running. I am trying to figure out how to do this in MVC Controller ActionResult event using LINQ
Usually something like
var strSQL ="SELECT field1, field3, field5 FROM tblWhatever WHERE 1-1"
(the 1=1 allows flexibilty in how many AND's I build, not having to worry about the first one)
then I build the string of ANDs or just one and concatenate
strSQL .= " AND DWPCEU != null "
strSQL .=" AND DEQCEU !=null "
then I run the SQL (in PHP)
Got any idea how I would build a string of ANDs in a Controller ActionResult?
this limited example below works, but only for one AND. I know I can add "&&"s ad nauseum but would rather build it elsewhere since there are 4x4 number of checkbox choices. There are 4 checkboxes and none, any, or all can be checked.
var courses = from m in _db.Courses select m;
if (!String.IsNullOrEmpty(searchString))
{
if (bolDWP == true)
{
courses = courses.Where(s => s.CourseTitle.Contains(searchString) **&& s.CEUDWP !=null**);
}
else
{
courses = courses.Where(s => s.CourseTitle.Contains(searchString));
}
}