实体框架Where方法 [英] entity framework Where method
本文介绍了实体框架Where方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在这方面我需要一些帮助,我该如何在我希望基于两列检索记录的地方编写where子句语句:
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();
}
但是此语句有错误.
-----高于解决方案------------
----- ABOVE SOLVED ------------
还有另一个问题:
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;
}
我得到错误,其中q不存在是当前上下文,我在这里试图做的是获取列的最大值(questionNo),其中taskname =列表任务,而activityid =列表活动.
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.
推荐答案
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();
}
新问题的答案:
在Where
子句中添加q =>
块.
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;
}
这篇关于实体框架Where方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文