我不知道为什么同时我在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'
类型的操作数
如何让这个查询起作用?
答案 0 :(得分:6)
试试这个:
from c in PriceListPolicies_TBLs
where
(
((c.CountryCode ?? "VNALL") == "VNALL" ? "VN" : c.CountryCode)
||
((c.CountryCode ?? "THALL") == "THALL" ? "TH" : c.CountryCode)
)
select c
答案 1 :(得分:3)
||
运算符只能应用于bool
和bool
c.CountryCode || (c.CountryCode ?? "THALL") // is wrong, since c.CountryCode is a string
答案 2 :(得分:1)
根据您的comment,您不需要条件。简单地做这样的事情:
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";
}
}