JayJay
JayJay

Reputation: 1068

Operator '||' cannot be applied to operands of type 'string' and 'bool'

I dont know why meantime i compile my query in linq as follows below

from c in PriceListPolicies_TBLs
where ((c.CountryCode ?? "VNALL")== "VNALL" ? "VN" : c.CountryCode || 
      (c.CountryCode ?? "THALL") == "THALL" ? "TH" : c.CountryCode) 
select c

gives this error

Operator '||' cannot be applied to operands of type 'string' and 'bool'

how can I get this query to work?

Upvotes: 3

Views: 6394

Answers (3)

cremor
cremor

Reputation: 6876

Based on your comment you don't want a condition. Simply do something like this:

var allItems = from c in PriceListPolicies_TBLs
               select c;

foreach (var c in allItems)
{
    if (c.CountryCode == "VNALL")
    {
        c.CountryCode = "VN";
    }
    else if (c.CountryCode == "THALL")
    {
        c.CountryCode = "TH";
    }
}

Upvotes: 1

sll
sll

Reputation: 62504

Try this:

from c in PriceListPolicies_TBLs 
where 
(
  ((c.CountryCode ?? "VNALL") == "VNALL" ? "VN" : c.CountryCode)
  || 
  ((c.CountryCode ?? "THALL") == "THALL" ? "TH" : c.CountryCode)
) 
select c

Upvotes: 6

Nolonar
Nolonar

Reputation: 6122

The || operator can only be applied to bool and bool

c.CountryCode || (c.CountryCode ?? "THALL") // is wrong, since c.CountryCode is a string

Upvotes: 3

Related Questions