我有这张桌子:
string[] arr1 = new string[] { "one", "two", "three" };
这个查询:
var result = (from i in dc.Ses
where i.id == id
select
new
{
id = i.id,
FullName = i.FullName,
Type = i.Type
}).ToList();
但我想改变result
,因此Type
将包含此arr1[i.Type]
。
因为i.Type
i.Type == null
可以为空,因此Type = null
也是
答案 0 :(得分:0)
Type = i.Type.HasValue ? arr1[i.Type] : null
编辑以拆分查询
var partialResult = (from i in dc.Ses
where i.id == id
select
new
{
id = i.id,
FullName = i.FullName,
RawType = i.Type
});
var finalResult = partialResult.AsEnumerable().Select(entry => new {
...
Type = entry.RawType.HasValue ? arr1[entry.RawType] : null
});