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 6103533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:44:23+00:00 2026-05-23T13:44:23+00:00

I have some items in database. Each of’em can have many tags, like Browsable,

  • 0

I have some items in database. Each of’em can have many tags, like Browsable, or IsInMenu and so on. A friend of mine suggested to use enums with Flags attribute to create an extensible solution. So, I created a field in DB which takes an integer value, then I created this enum:

 [Flags]
 public enum ItemTags { Browsable = 2, IsInMenu = 4}

Now I’d like to be able to semantically get the list of some items this way:

 public List<Item> GetItems(ItemTags tags)
 {
     /* 
     Code to get data from DB, something like, 
     return repository.GetList(tags);
     */
 }    

and in UI, I’d like to call:

 List<Item> items =  GetItems(ItemTags.Browsable | ItemTags.IsInMneu);

But I don’t get the desired result. Am I going the right way?
By desired result, I mean this:
Values stored in database could be one of the 0, 2, 4, 6 values now. 0 means that the item is not in Menu and also not Browsable. 2 Means that item is Browable, but not in Menu. 4 means item is in Menu, but not Browsable. 6 means item is both Browsable and IsInMenu. Now when I call GetItems function, I don’t get all the items which are browsable, in menu, or both browsable and in menu.

  • 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-05-23T13:44:24+00:00Added an answer on May 23, 2026 at 1:44 pm

    use the FlagsAttribute Class

    Indicates that an enumeration can be
    treated as a bit field; that is, a set
    of flags.

    [Flags] 
    public enum ItemTags 
    { 
      Default =0,
      Browsable = 2, 
      IsInMenu = 4,
      All = 6 // Browsable / IsInMenu
    }
    

    More here

    note about enums:

    an Enum by default has an int
    under­neath, and as do all inte­gers
    in C# an enum has a default value of 0
    when first cre­ated. So if 0 is not
    mapped to an enu­mer­a­tion con­stant
    then your enum will be instan­ti­ated
    with an invalid valid

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

Sidebar

Related Questions

I have many database entries, each containing a value. I want to show some
I have some items called tickers which can be created and subscribed to. When
I have some items that I'd like the user to be able to filter
i have some Orders that can have several Items and these Items have an
I have a ListView with some items. I have toggleButton in each row of
I am creating a JSF application. I have some items (e.g. products) from database
I have some rows in a database which represent line items in a sale.
I have some models like these: class Alpha < ActiveRecord::Base has_many :items end class
My grid view has some items I can remove each sucessfully by just writing
I have a large database of artists, albums, and tracks. Each of these items

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.