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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:12:19+00:00 2026-06-06T09:12:19+00:00

I’m trying to implement a TPC inheritance model in EF 4.3 CodeFirst for an

  • 0

I’m trying to implement a TPC inheritance model in EF 4.3 CodeFirst for an existing Oracle database (over which I have no control). I have several sub-types that each map to its own table. Unfortunately, some of the key columns are of datatype number(18,0) instead of integer. EF seems to hate me now.

Here’s my base class:

public abstract class Vehicle
{
    public virtual int Id { get; set;}
    public virtual string Color { get; set; }
    //more properties
}

Here are some example sub-types:

public class Car : Vehicle
{        
    //more properties
}

public class Truck : Vehicle
{
    //more properties
}

public class Motorcycle : Vehicle
{
    //more properties
}

And here’s my DbContet:

public class VehicleDataContext : DbContext
{
    public DbSet<Vehicle> Vehicles { get; set; }
    public DbSet<Car> Cars { get; set; }
    public DbSet<Truck> Trucks { get; set; }
    public DbSet<Motorcycle> Motorcycles { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Vehicle>().HasKey(x => x.Id);

        modelBuilder.Entity<Car>().Map(m => m.MapInheritedProperties());
        modelBuilder.Entity<Car>().Property(x => x.Id).HasColumnType("decimal");

        modelBuilder.Entity<Truck>().Map(m => m.MapInheritedProperties());
        modelBuilder.Entity<Truck>().Property(x => x.Id).HasColumnType("int");

        modelBuilder.Entity<Motorcycle>().Map(m => m.MapInheritedProperties());
        modelBuilder.Entity<Motorcycle>().Property(x => x.Id).HasColumnType("decimal");

        base.OnModelCreating(modelBuilder);
    }
}

So, I already know to MapInheritedProperties so that all the properties of the base and sub-type are mapped to one table. I’m assuming that I have to tell the base that it HasKey so that EF doesn’t complain that my DbSet<Vehicle> doesn’t have a key mapped. I’d like to be able to assume that I can “tell” each entity how to map its own key’s column type like I’ve done above. But I think that’s not quite it.

Here’s a test that fails:

[TestFixture]
public class when_retrieving_all_vehicles
{
    [Test]
    public void it_should_return_a_list_of_vehicles_regardless_of_type()
    {
        var dc = new VehicleDataContext();
        var vehicles = dc.Vehicles.ToList(); //throws exception here
        Assert.Greater(vehicles.Count, 0);
    }
}

The exception thrown is:

The conceptual side property ‘Id’ has already been mapped to a storage
property with type ‘decimal’. If the conceptual side property is
mapped to multiple properties in the storage model, make sure that all
the properties in the storage model have the same type.

As mentioned above, I have no control over the database and it’s types. It’s silly that the key types are mixed, but “it is what it is”.

How can I get around 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-06T09:12:20+00:00Added an answer on June 6, 2026 at 9:12 am

    You cannot achieve it through mapping. This is limitation of EF code first. You can map each property (including the key) in inheritance structure only once. Because of that you can have it either integer or decimal in all entities in the inheritance tree but you cannot mix it.

    Btw. what happens if you try to use int or decimal for the whole inheritance tree? Does it fail for loading or persisting entity? If not you can simply use the one (probably decimal if it can use whole its range) for all entities.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
I have a reasonable size flat file database of text documents mostly saved in
I am trying to loop through a bunch of documents I have to put
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,

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.