How to use flags enums in Linq to Entities queries?

后端 未结 8 1011
轮回少年
轮回少年 2021-01-01 04:33

I have a [Flags] enum like this:

[Flags]
public enum Status
{
  None = 0,
  Active = 1,
  Inactive = 2,
  Unknown = 4
}

A Status enum may c

8条回答
  •  -上瘾入骨i
    2021-01-01 05:11

    In DB Flags enum must be integer. After that you can try it like this:

    Status s = Status.Active | Status.Unknown;
    
    var result = from r in db.Records
    where (s & r.Status) == r.Status
    select r
    

提交回复
热议问题