运营商"&&"不能应用MVC

时间:2015-05-19 09:30:15

标签: c# asp.net asp.net-mvc linq asp.net-mvc-4

我想创建一个计数器方法,它计算每个位置停止的作业数。我尝试了它,如下所示,但我收到以下错误:

  

错误1运营商&&&'不能应用于' bool'类型的操作数和JobTracker.Models.Job' D:\ C#Web Application \ JobTracker-Dev2 FINAL \ JobTracker \ Controllers \ JobController.cs 126 46 JobTracker

我知道这与booleanInt比较有关,但我不知道如何在当前状态下解决它

public int Stopped()
{
    int Stopped = db.Jobs.Where(x => x.Status == "Stopped" && x => x.LocationID == 1).Count();
    return Stopped;
}

还有一种简单的方法可以将计数保存在一个方法中。我有大约20个这些单独的方法,我喜欢将它们全部放在一个方法中,然后我可以初始化该方法并在需要时调用每个变量

 public void Stopped()
{

    int HBAStop = db.Jobs.Where(x => x.Status == "Stopped" && x.LocationID == 1).Count();
    int CRStop =  db.Jobs.Where(x => x.Status == "Stopped" && x.LocationID == 2).Count();
    int MAStop =  db.Jobs.Where(x => x.Status == "Stopped" && x.LocationID == 3).Count();
    int QCStop =  db.Jobs.Where(x => x.Status == "Stopped" && x.LocationID == 4).Count();
    int LTStop =  db.Jobs.Where(x => x.Status == "Stopped" && x.LocationID == 5).Count();
    int PTStop =  db.Jobs.Where(x => x.Status == "Stopped" && x.LocationID == 6).Count();
    int SPStop =  db.Jobs.Where(x => x.Status == "Stopped" && x.LocationID == 7).Count();

}

我希望很清楚,请让我知道,如果需要,我会提供更多信息。

2 个答案:

答案 0 :(得分:5)

您需要删除x =>,因为您已经在启动where条件时提到过了。就是这样。

int Stopped = db.Jobs.Where(x => x.Status == "Stopped" && x.LocationID == 1).Count();

答案 1 :(得分:0)

你做错了你需要做的是:

int Stopped = db.Jobs.Where(x => x.Status == "Stopped" &&  x.LocationID == 1).Count();