鉴于以下枚举
[Flags]
public enum Trans{
Purchase =1,
Sale=2,
All = Purchase | Sale
};
和下面的课
public class Person
{
public string Name;
public Trans TransType;
}
以及以下数据结构
var people = new List<Person>();
people.Add(new Person {Name="James", TransType = Trans.Purchase});
people.Add(new Person {Name="Nancy", TransType = Trans.Sale});
people.Add(new Person {Name="Heather", TransType = Trans.All});
people.Add(new Person {Name="Duane", TransType = Trans.All});
我正在尝试查询满足某些条件的人的列表。
让所有人使用 Trans.Purchase (James, Heather & Duane)
var query = from p in people where ( (p.TransType & Trans.Purchase) == Trans.Purchase) select p;
通过 Trans.Sale 吸引所有人(南希、希瑟和杜安)
var query = from p in people where ( (p.TransType & Trans.Sale) == Trans.Sale) select p;
我需要在 LINQ 查询的 where 子句中指定什么以返回带有Trans.Purchase、Trans.Sale或两者(即 Trans.All)的每个人?(詹姆斯。南希,希瑟和杜安)
编辑 一些上下文 - TransType 存储在数据库中,并且正在尝试编写用户指定 TransType 的屏幕,并且 SQL 查询提取上述数据