Reputation: 1071
i need some help in this , how do i write a where clause statement where i want to retrieve record based on 2 columns :
This is how i am trying to write in code :
public IList<Model.question> GetAll(string search , int search1)
{
IList<Model.question> lstQuestions = context.questions.ToList();
return lstQuestions.Where(a => a.TaskName.Contains(search) && p => p.ActivityID.Contains(search1)).ToList();
}
but there is an error with this statement .
----- ABOVE SOLVED ------------
Heres another problem :
public int GetMaxValue(string listTask , int listActivity)
{
int maxQNo = Convert.ToInt32(context.questions.Max(q => q.QuestionNo).Where(q.TaskName.Contains(listTask) && q.ActivityID == listActivity));
return maxQNo+1;
}
i get the error where q doesn't exist is current context , what i am trying to do here , is to get the max value of the column ( questionNo) where taskname = list task and activityid = list activity.
Upvotes: 0
Views: 193
Reputation: 3821
public IList<Model.question> GetAll(string search , int search1)
{
IList<Model.question> lstQuestions = context.questions.ToList();
return lstQuestions.Where(a => a.TaskName.Contains(search) && a.ActivityID==search1)).ToList();
}
Answer of new problem:
Add q =>
block in Where
clause.
public int GetMaxValue(string listTask , int listActivity)
{
int maxQNo = Convert.ToInt32(context.questions.Max(q => q.QuestionNo)
.Where(q=>q.TaskName.Contains(listTask) &&
q.ActivityID.Contains(listActivity));
return maxQNo+1;
}
Upvotes: 1