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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:39:45+00:00 2026-06-04T13:39:45+00:00

I am working on some code that makes use of single table inheritance via

  • 0

I am working on some code that makes use of single table inheritance via EF4.3.

There is an entity called User and another entity called Admin. Admin inherits from user.

User class

public class User
{
    public int Id {get;set;}
    public string Username {get;set;}
}

Admin class

public class Admin : User { }

EF generated the database tables with a Discriminator column. When an Admin record is added then Discriminator="Admin" and a User record would have Discriminator="User".

My question is, how do I update the Discriminator column if I want to make a User into and Admin?

I tried casting from one object type to the other and saving using EF. but that doesn’t change the Discriminator column. How do I change it?

Thanks for any help.

  • 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-04T13:39:47+00:00Added an answer on June 4, 2026 at 1:39 pm

    Objects can’t change their types, ever. If you intend to change the “administrator” setting for a user (reasonable), you should do that with an attribute/property, not a type name.

    For example, you could have an association between a User object and an Administrator object, rather than wanting to replace the User object with an Administrator subtype.

    I wrote about this idea in an old blog post:

    One of the mental barriers that you have to get over when designing a good object relational mapping is the tendency to think primarily in object oriented terms, or relational terms, whichever suits your personality. A good object relational mapping, though, incorporates both a good object model and a good relational model. For example, let’s say you have a database with a table for People, and related tables for Employees and Customers. A single person might have a record in all three tables. Now, from a strictly relational point of view, you could construct a database VIEW for employees and another one for customers, both of which incorporate information from the People table. When using a one VIEW or the other, you can temporarily think of an individual person as “just” an Employee or “just” a Customer, even though you know that they are both. So someone coming from this worldview might be tempted to do an OO mapping where Employee and Customer are both (direct) subclasses of Person. But this doesn’t work with the data we have; since a single person has both employee and customer records (and since no Person instance can be of the concrete subtype Employee and Customer simultaneously), the OO relationship between Person and Employee needs to be composition rather than inheritance, and similarly for Person and Customer.

    To answer your question directly, there’s no way to change this column using EF. You could of course, do it in straight SQL. But for the reason given above, I’d encourage you to change this design.

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

Sidebar

Related Questions

I'm working with some legacy code that makes extensive use of this kind of
I'm working on some code that deals with parsing files (mainly XML, but there
I'm working with some legacy test code which makes use of a TestSetup class
I'm currently working on some C#/C++ code which makes use of invoke. In the
I'm working some code that inserts csv rows into an SQLite database using Python.
I'm working on some code that loads an xml file at run time. At
I am working on some code that previously was using a cfquery, and is
I'm working on some existing c++ code that appears to be written poorly, and
I'm working on some code which fills a GridView full of images that have
I have some code I am working on that worked just fine until I

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.