IQueryable items = from rr in _dt.AllItems
where rr.ID == ItemID
select new{rr.Item, rr.SecondItem};
SecondItem返回false或true。是否可以用不同的字符串值替换(例如使用On和Off)并添加到项目(IQueryable)?
答案 0 :(得分:2)
你可以这样做:
IQueryable items = from rr in _dt.AllItems
where rr.ID == ItemID
select new {
rr.Item,
SecondItem = rr.SecondItem.HasValue ? "Off" : rr.SecondItem ? "On" : "Off"
};
答案 1 :(得分:1)
你的意思是
var items = from rr in _dt.AllItems
where rr.ID == ItemID
select new
{
rr.Item,
rr.SecondItem == true ? "On" : "Off"
};
答案 2 :(得分:1)
IQueryable items = from rr in _dt.AllItems
where rr.ID == ItemID
select new {
rr.Item,
SecondItem = rr.SecondItem.Value ? "On" : "Off"
};