WPF C# LINQ:运算符“&&”不能应用于“字符串”和“字符串”查询类型的操作数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21631840/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 10:46:00  来源:igfitidea点击:

WPF C# LINQ: Operator '&&' cannot be applied to operands of type 'string' and 'string' query

c#sqlwpflinq

提问by kknaguib

I'm trying to execute this query but for some reason it doesn't like the fact that 2 strings are sitting beside each other, here's the query:

我正在尝试执行此查询,但由于某种原因,它不喜欢 2 个字符串并排放置的事实,这是查询:

var FiveSecStatsQuery = from qai in connection.QuickAnalyzerInputs
                             join calP in connection.CalculatedPrices on qai.InputID equals calP.TradeID
                             where ***(qai.ClientName = clientName) && (qai.CurrencyPair = cur_pair)*** 
                             && (calP.Description = PriceDescriptions.FiveSeconds) && (calP.Outcome != null)
                             select new
                             {
                                 calP.Outcome
                             };

The error is : Operator '&&' cannot be applied to operands of type 'string' and 'string'

错误是:运算符“&&”不能应用于“字符串”和“字符串”类型的操作数

Why is it giving me this error? Both ClientName and CurrencyPair are of type string in the database. The error occurs where the asterisks are

为什么给我这个错误?ClientName 和 CurrencyPair 在数据库中都是字符串类型。错误发生在星号所在的位置

回答by Habib

You need double ==, not single =so your whereclause should be:

你需要 double ==,而不是 single ,=所以你的where条款应该是:

where (qai.ClientName == clientName) && (qai.CurrencyPair == cur_pair)
&& (calP.Description == PriceDescriptions.FiveSeconds) && (calP.Outcome != null)

回答by Tamir Vered

Change (qai.ClientName = clientName) && (qai.CurrencyPair = cur_pair)to (qai.ClientName == clientName) && (qai.CurrencyPair == cur_pair)since its boolean operation not value assignment

更改(qai.ClientName = clientName) && (qai.CurrencyPair = cur_pair)(qai.ClientName == clientName) && (qai.CurrencyPair == cur_pair)因为它的布尔运算不是赋值