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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:33:35+00:00 2026-06-02T08:33:35+00:00

Instead of splitting each permission into individual columns or sql server table we are

  • 0

Instead of splitting each permission into individual columns or sql server table we are rethinking of using Flag attribute to Enum for use with bit wise operations. Our application defines end points ( not the one from rest services) for accessing resources( read, modify, update) and each user is entitled with permissions for example Bob has permissions to Read, Modify resource X so when bob comes and accesses this resource we check if bob has permission x.Now that where we are going to apply this is clear here are my doubts

  • Suppose Bob has Read, Write, Delete permission on resource using Flagged enumerations i would do Permission.Read | Permission.Write | Permission.Delete Is the end result of bit wise AND a integer or another Enum ?

  • For Storing this permission in database table should the column be a integer?

  • If answer to question 1 is Enum then should i define another property on the Permissions enum that represents the integer value of Bit wise and operation?

disclaimer: the Bob referred to in the example does not represent any user in the Stack overflow network of sites or any person. It is just another character

  • 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-02T08:33:36+00:00Added an answer on June 2, 2026 at 8:33 am

    To answer your questions in order:

    • Assuming you have set the [Flags] attribute on the enum, and use the correct operator (& and | for bitwise operations) it is essentially both. If you cast the result to an integer, you will get the bitwise and of the relevant values, ie. 7 for your example. If you use .ToString(), then you will get a string back indicating that the value has all three values. I believe that there is a HasFlags() method somewhere, but most code I have seen uses the tried and true bitwise code for comparisons, ie:

      var x = Permissions.Read | Permissions.Write;
      if ((x & Permissions.Read) == Permissions.Read) { print "Success!"; }
      

      From a technical standpoint, C#’s type safety helps keep things sane and the result of |ing or &ing two enums of the same type is another enum of the same type but all enums are simply integers, and can be treated as such in most cases, though some things need explicit casts to/from int.

    • It should be an integral type, yes. I believe the default type for an enum is Int32, however you can set that explicitly if you want to match up the database and code exactly.

    • Given all the above, it can still make a lot of sense to have predefined values for commonly used sets of permissions, for example ReadWrite. In particular, a None element is recommended for all enums by Microsoft, especially if you are going to be casting values. This allows for a fallback and a valid value for freshly initialized variables as well as a sane value for default(Permissions). You can set values in your enum based on other ones like so:

      [Flags]
      enum Permissions {
        None =    0,
        Read =    0x001,
        Write =   0x010,
        Execute = 0x100,
        ReadWrite = Read | Write,
        // [snip]
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just figured this out but instead of splitting my new question (why?) into
Instead of using an interface like this: public interface IStartable { void Start(); void
Instead of just using urllib does anyone know of the most efficient package for
Instead of going through each (+) sign at the left and clicking them to
Instead of using an external web-based Mercurial host, I want to set one up
How can I make vertical splitting the default instead of horizontal splitting in Emacs?
I am doing some text processing, part of it is splitting words into single
I am working on splitting an MVC3 Application into two Areas. The existing application
Is there a nice linqy way of splitting a FormCollection into a Dictionary<string,string> that
Good programming practice these days tends to mean splitting your stuff up into lots

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.