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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:22:29+00:00 2026-05-11T01:22:29+00:00

If a flag IsAdmin, cast as AdminUser otherwise cast as NormalUser. Was just curious

  • 0

If a flag IsAdmin, cast as AdminUser otherwise cast as NormalUser.

Was just curious about this but not sure how to do it. I do see that you can create a child object based on a table value and another table like:

SiteUser is from the table Site_User AdminUser is from the table Site_User and Admin_User when Site_User.IsAdmin = true

However, I was curious if you could do this:

If IsAdmin is true, cast as AdminUser otherwise cast as NormalUser where AdminUser : SiteUSer and NormalUser : SiteUser BUT there isn’t a Admin_User table or Normal_User table. This is strictly a casting based off the same table and a column value. The types hold no additional information, just would be helpful for situations like:

SomeMethod(SiteUser someUser) {     if(someUser is AdminUser)     {        ...     }     else     {        ...     } } 

Instead of:

SomeMethod(SiteUser someUser) {     if(someUser.IsAdmin)     {        ...     }     else     {        ...     } } 

Now I realize this may not be the best example, but say the flag is a multiple value property so instead of:

SomeMethod(SiteUser someUser) {     swith(someUser.Role)     {         case(1):           break;         case(2)           break;     } } 

Of course this just might be a bad idea anyhow, but was wondering if it is possible.

  • 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. 2026-05-11T01:22:29+00:00Added an answer on May 11, 2026 at 1:22 am

    Entity framework supports Table-Per-Type and Table-Per-Hierarchy inheritance.

    Table-Per-Type means that a new table is used for each class, including the abstract type. Table-Per-Hierarchy means that a single table is used to store data for multiple types, and only the columns necessary for that type are pulled from the single table.

    Either way, an object can be tested just the way you are describing.

    if (someUser is AdminUser) {    ... } else {    ... } 

    More information on using both of these can be found here, and they both are supported visually in the Entity Framework designer:

    Table-Per-Type

    Table-Per-Hierarchy

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

Sidebar

Related Questions

I was reading about flag enums and bitwise operators, and came across this code:
I see this flag a lot in the makefiles. What does it mean and
I saw something that was a red flag for me when I ran this:
How would I go about creating a flag so that if a service is
If flag is true I have to perform step no. 1 otherwise skip it.
I have a flag attached to my UserProfile record for logged in users that
Is there a flag for gcc such that conversions from a long to a
Before you flag this as a duplicate, I've read the other question , and
I know about flag -XX: PretenureSizeThreshold which can be used to set to limit
What type of parameter/flag can I use with the Unix find command so that

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.