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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:27:19+00:00 2026-06-10T20:27:19+00:00

I have a base class and there are derived classes. The base class is

  • 0

I have a base class and there are derived classes. The base class is mapped to a table using EF4 TPH(Table-per-hierarchy). In my application, the user can select one of the many derived classes and then I need to save them with the “Discriminator” column correctly populated.

On the UI the user enters Id & Name only (base class properties) and hence I am storing user entries in a list of base class objects. Since I get to know which derived type the user has selected at run time, I am not sure how to do this.

So far I’ve tried using Convert.ChangeType on the base objects to get the derived class object and then doing an Add to the entity. But it fails with “Object must implement IConvertible.”

Not sure what else can I do. Any ideas? Thanks.

  • 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-10T20:27:20+00:00Added an answer on June 10, 2026 at 8:27 pm

    Use var derivedEntity = Activator.CreateInstance(typeof(YourDerivedType)); then attach it.

    Or better still, let entity framework do it for you:

    var entity = Context.Set<TEntity>().Create();
    

    Where Context is your DbContext.

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

Sidebar

Related Questions

I have a base class and there are few classes being derived from it.
Let's say I have a Base class and several Derived classes. Is there any
I have a base class Rules.cs . There are 2 derived classes RowRules.cs and
I have some hierarchy: base, derived classes and some structure storing user data as
I have a simple question. There is a base class Product. And derived classes
I have these classes: class Base { ... private: std::vector<X> v; }; class Derived
I have a base class and several derived classes. The derived classes use some
I have a base class Element and derived two other classes from it, Solid
In C#, I have a class hierarchy with a couple of abstract base classes
I have a base class and a dozen derived classes. All but one derived

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.