gpt4 book ai didi

c# - 运算符 "&&"无法应用MVC

转载 作者:行者123 更新时间:2023-12-02 14:01:06 24 4
gpt4 key购买 nike

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

Error 1 Operator '&&' cannot be applied to operands of type 'bool' and 'JobTracker.Models.Job' D:\C# Web Application\JobTracker-Dev2 FINAL\JobTracker\Controllers\JobController.cs 126 46 JobTracker

我知道这与 boolean 有关。和一个Int比较,但我不知道如何在当前状态下解决它

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();

}

我希望这是清楚的,否则请告诉我,如果需要,我会提供更多信息。

最佳答案

您需要删除 x =>,正如您在 where 条件开始时提到的那样。就是这样。

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

关于c# - 运算符 "&&"无法应用MVC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30321732/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com