3

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

2 Answers 2

16

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)
Sign up to request clarification or add additional context in comments.

2 Comments

Wowww! thanks been staring at it for 15 min and I couldn't see that. Thanks again @Habib!
Where(m=> (m.zdjh == msn).ToString() && (dt >= m.sjsj).ToString() this is my LINQ exp and I am getting operator && cannot be applied to operands of type 'string' and 'string' c#
4

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.