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

10,511

Solution 1

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)

Solution 2

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

Share:
10,511
kknaguib
Author by

kknaguib

Updated on June 28, 2022

Comments

  • kknaguib
    kknaguib almost 2 years

    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

  • kknaguib
    kknaguib about 10 years
    Wowww! thanks been staring at it for 15 min and I couldn't see that. Thanks again @Habib!
  • Moeez
    Moeez over 6 years
    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#