我需要使用按位运算符查询表以生成字典结果。在谈到LINQ时,我远非专业人士,我有以下几点:
return (Dictionary<string, bool>) (from r in db.LocationVisibilities
where (r.Code & (int) permissionLevel) != 0 //bitwise statement in where clause
select new
{
r.Item, value = Boolean.Parse(r.Attribute.ToString())
});
答案 0 :(得分:0)
您不能将查询转换为类似的字典,您可以调用ToDictionary
函数,它将为您处理所有细节。
var dict=
(from r in db.LocationVisibilities
where (r.Code & (int) permissionLevel) != 0 //bitwise statement in where clause
select new {
r.Item, value = Boolean.Parse(r.Attribute.ToString())
}).ToDictionary(w=>w.Item, w=>w.value);