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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:21:26+00:00 2026-05-27T00:21:26+00:00

I have a situation where I have 4-5 very similar classes which I’d like

  • 0

I have a situation where I have 4-5 very similar classes which I’d like to re-factor to use an abstract base class.
The idea behind this would be allow methods which could be used by each class whilst adhering to DRY principles.

The problem I have is that these classes are Entity classes generted from EF4 and each time I try to alter my model it seems to break down.

What’s the best/recommended, method to add a base class into my EF model and make the existing classes in the model inherit from this as a base? At the moment I’ve got no problem adding the base class, giving it an ID property as it seems to require, and then creating the inheritence, but EF then moans about

'Error 3024: Problem in mapping fragments starting at line 18563:Must specify mapping for all key properties (MyBaseType.ID) of the EntitySet MyBaseType.'

In this situation I don’t want the base type to be persisted to the DB, purely used as a container for base methods common to all the classes which inherit from it. It feels like I’m missing something simple here but I can’t for the life of me see it.

Any ideas on how to add in a base class in this way? Or should I just be adding the base class in code and bypassing the model somehow?

EDIT: As further information, take an example where there are say 3 types, MortageApplicationForm, BankAccountApplicationForm and CreditCardApplication form. They are currently stored in 3 different tables, with a set of different fields.
What I’m trying to do, is create a base class of say ‘Form’ which will have the common fields in it.

At a simple level, say that each table has a primary key ID field called, ‘CreditCardFormID’, ‘BankAccountFormID’ etc What I’d like to do it create a base ‘Form’ class with a property ‘ID’ which for the case of one table will map to ‘CreditCardFormID’ and another ‘BankAccountFormID’.

I’m happy to do this mapping in partial classes (as I don’t want to persist ‘ID’ to the DB) I simply want to use it in code, so I can write generic methods for things like LoadForm(int ID) without needing to write huge switches for each entity type, or specific methods for each entity type.

  • 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-05-27T00:21:27+00:00Added an answer on May 27, 2026 at 12:21 am

    I managed to find a work around for this by rejigging things slightly. Firstly, I did not have the time available to rework the model (which I think would have been the best solution) too much of the system has already been developed with the existing structure to rip it all apart at this point.

    The solution so far, has been to create a static helper class to contain business logic which is generic accross in my example, the 3 different account types.

    This was coupled with an ‘IAccount’ interface, allowing the helper class to take an IAccount instance as a parameter (allowing the passing of any particular account type.) This interface contained all the common properties accross the 3-4 concrete classes. It was important to note that in order to create generic methods which I could call on all the classes I was not able to use any other properties specific to the class.

    Within the helper methods, I needed to switch my concrete XYZEntities instance to a more generic ‘ObjectContext’ object and then use the methods such as ‘AddObject’ rather than ‘AddBankAccountForm’, ‘AddCreditCardForm’ etc explicitely.
    This involved a tiny bit of GetType()’ing to ensure the object was passed to the correct ObjectSet, but seems to work as desired.

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

Sidebar

Related Questions

I have a very similar situation to the person who asked: Can I serve
I have an situation here that looks very like a SELECT N+1 from the
So I have a situation very similar to this (much simplified) code: import Data.Maybe
I have a very similar situation to what's described in this question : Engineer
Current situation: I have the current version of my MVC Framework which uses classes
I have a situation very similar to the one in this question: Selective Cache
My situation is very similar to this question . I have an app that
I have a situation where I am loading a very unnormalized record set from
The situation is very simple, I have two panel. In the event of OnMouseOver
I have a very strange situation. I have a large set of records to

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.