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

  • Home
  • SEARCH
  • 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 3232544
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:10:25+00:00 2026-05-17T17:10:25+00:00

I have the following enum: [Flags] public enum PostAssociations { None = 0x0, User

  • 0

I have the following enum:

[Flags]
public enum PostAssociations
{
    None = 0x0,
    User = 0x1,
    Comments = 0x2,
    CommentsUser = 0x3
}

As a starting note, im not sure if those flags are correct.

I’m doing this so that i have a fluent way of defining “Includes” for Entity Framework (as the EF Include method takes a string, which i dont want exposed to the UI).

So i want it so my service layer can accept a PostAssociations, and in my service layer i utilize an extension method to convert this to a string[]. (which my repo then splits up in order to do the .Include).

I haven’t done much with Flags Enum’s, so i apologize for my ignorance. 🙂

This is a “truth-table” of what i want (enum value, transformed string[])

None = null
User = new string[] { "User" }
Comments = new string[] { "Comments" }
User, Comments = new string[] { "User", "Comments" }
Comments, CommentsUser = new string[] { "Comments", "Comments.User" }
User, Comments, CommentsUser = new string[] { "User", "Comments", "Comments.User" }

Cannot have CommentsUser without Comments.

So i need help with three things:

  1. How to setup the enum to match that truth table?
  2. How do i call the service layer for one of those examples?
  3. How do i write an extension method to convert that enum to the string array?

Of course, if you guys can think of a better way to do what im trying to do, i’ll consider that too. Essentially i’m trying to mask away the “magic strings” of the EF Include behind an Enum, and considering you can do multiple includes (or none), i thought this was a good case for a Flags Enum.

Thanks guys.

  • 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-17T17:10:25+00:00Added an answer on May 17, 2026 at 5:10 pm

    My bad guys, my inexperience with flags enums has resulted in a confusing question.

    My scenario isn’t valid for flags enum.

    Instead, i have opted to use a PostAssociations[].

    My service layer:

    public Post FindSingle(int postId, PostAssociations[] postAssociations)
    {
       return repo.Find(postAssocations.ToEfInclude()).WithId(postId);
    }
    

    The extension method:

    public static string[] ToEfInclude(this PostAssociations[] postAssocations)
    {
        if (postAssocations == null) return null;
    
        List<string> includeAssociations = new List<string>();
    
        if (postAssocations.Contains(PostAssociations.User))
            includeAssociations.Add("User");
        if (postAssocations.Contains(PostAssociations.Comments))
        {
            if (postAssocations.Contains(PostAssociations.CommentsUser))
            {
                includeAssociations.Add("Comments.User");   
            }
    
            includeAssociations.Add("Comments");
        }
    
        return includeAssociations.ToArray();
    }
    

    Usage:

    PostAssociations[] associations = new[] { PostAssociations.Comments, PostAssociations.User, PostAssociations.CommentsUser };    
    return service.Find(1, associations);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following enum: [Flags] public enum PermissionLevel { User = 1, Administrator
I have enum like this [Flags] public enum Key { None = 0, A
I have this enum: [Flags] public enum ExportFormat { None = 0, Csv =
I have the following enum declared: public enum TransactionTypeCode { Shipment = 'S', Receipt
I have the following enum: public enum Status implements StringEnum{ ONLINE(on),OFFLINE(off); private String status
I have the following enumeration: public enum AuthenticationMethod { FORMS = 1, WINDOWSAUTHENTICATION =
I have following enum definition public enum UploaderType { BrandLogo = 0, ReportingLogo =
From time to time I see an enum like the following: [Flags] public enum
Let's say I have the following simple enum: enum Response { Yes = 1,
I have following situation: I have loged user, standard authentication with DB table $authAdapter

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.