C# Multiple Linq Query Search Issue -
I have multiple linq queries for searching the database of information based on a specific specific criteria for the query like ID or By name etc.
Currently, the user can only search using a query method. The problem is that I want users to be able to use multiple parameters, without even writing new questions, can combine criteria with many questions.
For example:
I is a query that returns a set of questions based on those department names under which they are stored, and another query Which gives returns to a set of questions based on the module title under which questions are stored. Since the user can currently search only by the name of the department or the module title - e.g. Computer Science or Distributed Systems, I would like to change this so that the user can specify something like this:
Return all questions, Department name == Computer Science & amp; Amp; ModuleTitle == Distributed Systems
Help will be greatly appreciated.
Here is the current code:
// Department name questions public static IQueryable SearchByDepartmentNameInfo (string deptName) {ExamineDataContext DC = new testDataText (); Var queryResult = dcGetTable in q with & lt; Question & gt; () Where q.Topic.Module.Department.DepartmentName.Equals (deptName) are included in d.Colutions is equal to q.QuestionID in q.QuestionID qs // Note group selection new {module = q.Topic.ModuleTitle , Topic = q.TopicName, question = q.QuestionText, question type = q.QuestionType;}; Return query result; } // module title query public static IQueryable SearchByModuleTitleInfo (string modTitle) {ExamineDataContext DC = new ExaminationDataContext (); Var queryResult = q to dc.GetTable & lt; Question & gt; () Where q.Topic.Module.ModuleTitle.Equals (modTitle) is included in dc.Solutions in q. QuestionID equals s.QuestionID qs // Note group selection new {module = q.Topic.ModuleTitle, topic = q.TopicName, question = q.QuestionText, question type = q.QuestionType;}; Return query result; }
You can add them to a single query, only if this condition is set :
where (cond1 == "" || row.field1 == cond1) & amp; Amp; (Cond2 == ""; row.field2 == cond2) ... So if you search for cond1 = "" and cond2 = "somevalue", then you actually Only search on cond2 but if you specify both, then it will select the interaction of both the positions.
Add some checks to make sure at least one condition is specified.
Comments
Post a Comment