3

その間に、次のようにlinqでクエリをコンパイルする理由がわかりません。

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

このエラーが発生します

演算子'||' タイプ「string」および「bool」のオペランドには適用できません

このクエリを機能させるにはどうすればよいですか?

4

3 に答える 3

6

これを試して:

from c in PriceListPolicies_TBLs 
where 
(
  ((c.CountryCode ?? "VNALL") == "VNALL" ? "VN" : c.CountryCode)
  || 
  ((c.CountryCode ?? "THALL") == "THALL" ? "TH" : c.CountryCode)
) 
select c
于 2013-02-21T09:54:15.990 に答える
3

演算子はとに||のみ適用できますboolbool

c.CountryCode || (c.CountryCode ?? "THALL") // is wrong, since c.CountryCode is a string
于 2013-02-21T09:53:53.590 に答える
1

あなたのコメントに基づいて、条件は必要ありません。単純に次のようにします。

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";
    }
}
于 2013-02-21T11:17:41.370 に答える