【发布时间】:2015-05-28 12:01:33
【问题描述】:
我正在尝试使用 Linq 查询从数据库中获取记录列表。
public void Main() {
var filter = new Filter();
filter.ReceiverState = new List<DocumentState> { DocumentState.Completed };
var q = from d in Documents
where filter.ReceiverState.Any(f => (d.ReceiverState & (int)f) != 0)
select d;
q.Dump();
}
public class Filter {
public List<DocumentState> ReceiverState { get; set; }
}
[Flags]
public enum DocumentState {
Sent = 1,
NeedClarification = 2,
Completed = 4,
NeedResign = 8
}
但我收到此错误:
本地序列不能在查询运算符的 LINQ to SQL 实现中使用,但 Contains 运算符除外
我必须在过滤器中使用标记枚举列表。如何进行正确的 Linq 查询?
【问题讨论】:
-
请格式化您的代码。
-
您的查询有一些异味,1 您初始化过滤器和 filter.ReceiverState,但是在您的 linq 中您检查过滤器是否为空或 filter.ReceiverState 是否包含完成状态,该状态将始终为真.