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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:21:11+00:00 2026-06-13T23:21:11+00:00

I use EF 5 with the code first approach. Now I try to define

  • 0

I use EF 5 with the code first approach. Now I try to define a “code” table in which I want to have several different codes (like address code, medium code, etc.). In this table I just have the following properties: ID (Guid), Name (String), Description (String) and a discriminator (in this case something like the type of the code: address code, medium code, etc.).

So I defined the following base class:

public abstract class Code : EntityBase
{
    public string Name { get; set; }
    public string Beschreibung { get; set; }
}

Then I derived two classes from code

public class AddressCode : Code {}
public class MediumCode : Code {}

The class EntityBase is abstract and just defines the Id property, we use it for every POCO class…

The goal is that I can use AddressCode as a property on my address POCO class:

public class Adresse : EntityBase
{
    #region Properties
    public string Name1 { get; set; }

    public virtual AddressCode AddressCode { get; set; }
    #endregion
}

The question now is, how can I explain EF how to do that? Anyone can help?

Thanks
Marco


Thanks for your answer!

I tried to do it like you said. Unfortunately I get an error because of my EntityBase class:

public abstract class EntityBase
{
    #region Properties

    public virtual Guid Id { get; set; }

    public virtual bool IsValid
    {
        get
        {
            {
                return Validate();
            }
        }
    }

    [NotMappedAttribute]
    public virtual IList<ValidationFailure> ValidationFailures { get; set; }

    #endregion

    #region Methods

    private bool Validate()
    {
        var validatorFactory = new AttributedValidatorFactory();
        IValidator validator = validatorFactory.GetValidator(GetType());

        if (validator == null)
        {
            return true;
        }

        ValidationResult validationResult = validator.Validate(this);

        ValidationFailures = validationResult.Errors;

        return validationResult.IsValid;
    }

    #endregion
}

The error message is:
You cannot use Ignore method on the property ‘ValidationFailures’ on type ‘Entities.AdresseCode’ because this type inherits from the type ‘Entities.EntityBase’ where this property is mapped. To exclude this property from your model, use NotMappedAttribute or Ignore method on the base type.

As you can see I already defined the property ValidationFailures as NotMapped but still I get this error.. Do you have an idea?

Thanks
Marco

  • 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-13T23:21:12+00:00Added an answer on June 13, 2026 at 11:21 pm

    Just create a context (derived from DbContext)

    public class AddressesDb : DbContext
    {
        public DbSet<Code> Codes { get; set; }
        public DbSet<Adresse> Adressen { get; set; }
    }
    

    And (when used in code) EF will create a database with default table and column names. It will create a discriminator column of type text (nvarchar) which will contain the names of the classes that derive from Code.

    If you want different names and/or types you should either use data annotations or fluent API to configure these.

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

Sidebar

Related Questions

I have several Entity Framework Code First DbContext objects that use a custom Initializer.
I use Entity Framework code-first. DataBaseName - I want to create a database in
Here's sample model classes, which being use with Entity Framework Code First: public class
I am creating a project that uses EF Code First approach and now I
I use EF 4.2 code first in my mvc3 project. miniprofiler works fine (sql
First off I use this code to make the navigation bar always stay fixed;
I use this code to determine checkbox width and height: var chk = $('input[type=checkbox]:first');
First the requirements: By management requirements, I can't use open source code. I need
I want to use code beside files for my views in my ASP.NET MVC
I'm starting to play around with the code-first approach to the entity framework, primarily

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.