Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8487701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:19:22+00:00 2026-06-10T21:19:22+00:00

I have a flag e.g. [Flags] public enum DaysOfTheWeek { Monday = 1, Tuesday

  • 0

I have a flag e.g.

[Flags]
public enum DaysOfTheWeek
{
    Monday = 1,
    Tuesday = 2,
    Wednesday = 4,
    Thursday = 8,
    Friday = 16,
    Saturday = 32,
    Sunday = 64
}

If I want to use Linq to filter based on a variable containing particular flags, I can try to useEnum.HasFlag in a lambda statement to filter for more than one flag e.g.

DaysOfWeek weekendFilter = DaysOfTheWeek.Saturday | DaysOfTheWeek.Sunday;
var weekends = allDays.Where(d => d.DayOfWeek.HasFlag(weekendFilter));

This currently gives:

LINQ to Entities does not recognize the method ‘Boolean HasFlag(System.Enum)’ method, and this method cannot be translated into a store expression.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T21:19:23+00:00Added an answer on June 10, 2026 at 9:19 pm

    Enum flags are based on binary operations.

    HasFlag = (allDays & (DaysOfTheWeek.Saturday | DaysOfTheWeek.Sunday)) != 0;
    

    You can abstract that into an extension method if you wish.

    To answer your question concretely:

    DaysOfWeek weekendFilter = DaysOfTheWeek.Saturday | DaysOfTheWeek.Sunday;
    var weekends = allDays.Where(d => (d.DayOfWeek & weekendFilter) != 0);
    

    I know that you can use this predicate with LINQ to SQL. It will be translated to SQL (SQL Server supports binary arithmetic just fine). Not sure if EF is equally capable as its LINQ supports is generally far inferior to L2S.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a flag enum below. [Flags] public enum FlagTest { None = 0x0,
I have an enumeration with [Flag] attribute set on it. [Flags] public enum PageTags
I have a flags enum defined like this: [Flags] public enum MyEnum { None
I want design a flag enum but shared by two use cases: Use case
Possible Duplicate: When you use flag(Enum) you have a limit of 64. What are
Initially I had the following: [Flags] public enum QueryFlag { None = 0x00, CustomerID
Initially I had the following: [Flags] public enum QueryFlag { None = 0x00, CustomerID
The system have a plain enum like this, public enum SomeEnum : short {
I have a grid of Enum Flags in which each record is a row
I am currently trying to use a bit flag enum in a VB6 /

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.