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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:09:14+00:00 2026-06-03T01:09:14+00:00

I have two classes, Client and Author , that are both derived from Member

  • 0

I have two classes, Client and Author, that are both derived from Member. They add nothing to Member, but I prefer to have separate classes for semantics and possible later extension. I differentiate based on roles, where an Author is a Member that has an AuthorRole membership, and a Client is a Member that has a ClientRole membership. Using plain vanilla TPH mapping with a discriminator column precludes a Member being both a Client and an Author.

The only way I can see to resolve this is to have a ClientRepository and AuthorRepository do the mapping, with my db context blissfully unaware of any inheritance, but here I take a performance hit, because e.g. a ClientRepository will have to query for Member instances and map these to Client instances.

Is there some other way to do this?

  • 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-03T01:09:15+00:00Added an answer on June 3, 2026 at 1:09 am

    TPH mapping in EF says that client is member and author is member but there can be never a member who is client and author. There even cannot be a member who will change the role from client to author or vice versa.

    If you want to store two derived classes in the same table you must use TPH and discriminator. EF will ensure that preceding rules are ensured. If any of those rules is not valid in your scenario inheritance is a bad design for you anyway because even .NET will not allow you changing the type of the instance from client to member.

    If you want to keep your current design you will have to use client repository and additional level of mapping to your custom classes because EF is not able to drive TPH inheritance through relation. In EF meaning such inheritance cannot exists because you can change the relation but you cannot change the type of already created instance.

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

Sidebar

Related Questions

I have two classes generated by LINQ2SQL both from the same table so they
I have two classes that refer to each other, but obviously the compiler complains.
I have two different classes deriving from one base class. They each have a
I have two classes that I would like to merge into a composite. These
I have two classes one of which inherits from the other. Im trying to
I have two classes that I am testing (let's call them ClassA and ClassB).
I am working on a simple Core Data app. I have two classes: Client
I have two classes (Person and Address) that i need to send via wcf,
I have two classes; one is a server, another one is a client, and
I have two Core Data entities ( Client and UserFile ) that I have

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.