0

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.

0

1 Answer 1

1
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;
}
Sign up to request clarification or add additional context in comments.

6 Comments

Hi there , thanks for the fast reply , but my ActivityID is a INT in db , i tried to use int search1 but it gives me an error Instance argument: cannot convert from 'int?' to 'System.Linq.ParallelQuery<int>' and 'int?' does not contain a definition for 'Contains' and the best extension method overload 'System.Linq.ParallelEnumerable.Contains<TSource>(System.Linq.ParallelQuery<TSource>, TSource)' has some invalid arguments
@user2376998: if ActivityID is INT then why your search1 variable is string? it should be also INT? Right?
yeah sorry , forgot to changed it
@user2376998: I've updated my answer. Contains is replaced by ==. Please check now.
hi there , thanks for the answer , but i got another question to ask u , duno if its appropriate , sorry if it is ... new to stackoverflow .... the question is updated above.. hope u can take a look thanks
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.