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 have this tiny flag that I am using for an icon on the
I expected that this flag should be used together with dontcopy - to make
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
Python has a flag -O that you can execute the interpreter with. The option
Which flag should i use for create a file if not exists? Please not
Is there a compiler flag that makes GCC output errors in MSVC style? GCC
What is this flag? if (-M ..filepath..) what is the '-M' flag?
Is the O_LARGEFILE flag needed if all that I want to do is write
If flag is true I have to perform step no. 1 otherwise skip it.

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.