kknaguib
kknaguib

Reputation: 749

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

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:

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

Upvotes: 3

Views: 10863

Answers (2)

Tamir Vered
Tamir Vered

Reputation: 10287

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

Upvotes: 4

Habib
Habib

Reputation: 223267

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

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

Upvotes: 16

Related Questions