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

Ask A Question

Stats

  • Questions 74k
  • Answers 75k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Short Answer: The part of the file already transferred is… May 11, 2026 at 2:33 pm
  • added an answer Drools (used to be Drools then JBoss Rules then Drools… May 11, 2026 at 2:33 pm
  • added an answer Fusebox 5.1 allows you to use SES URLs by allowing… May 11, 2026 at 2:33 pm

Related Questions

I am working on a reliable file transfer program that uses UDP. (for a
Of the two methods below, which do you prefer to read? Is there another
The code that I want to write is like this: void MethodOnThreadA() { for
I'm piecing together an image website. The basic schema's pretty simple MySQL, but I'm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.