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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:23:15+00:00 2026-06-10T09:23:15+00:00

I have the following data structure: //property Notification abstract class BindableBase { } //base

  • 0

I have the following data structure:

//property Notification
abstract class BindableBase { }
//base class for all tenant-scoped objects
abstract class TenantModelBase : BindableBase 
{ 
  int TenantId;
} 

abstract class Order : TenantModelBase 
{
   Customer Customer; //works: mapped using TenantId and CustomerId
   Product Product; //again, works with TenantId and ProductId
   string ProductId;
   string CustomerId;
}
class Customer: TenantModelBase 
{
   string CustomerId; 
}

class Product  : TenantModelBase 
{
   string ProductId;
}

class SpecialOrder : Order
{
    OtherClass OtherClass; //this fails!, see below
    string OtherClassId;
}
class SuperSpecialOrder : SpecialOrder {  }

class OtherClass  : TenantModelBase 
{
    string OtherClassId;
}

I get the following error:

The foreign key component ‘TenantId’ is not a declared property on
type ‘SpecialOrder’. Verify that it has not been explicitly excluded
from the model and that it is a valid primitive property.

Error occurs using the Fluent Api Configuration:

        config.HasRequired(p => p.OtherClass)
            .WithMany(oc => oc.SpecialOrders)
            .HasForeignKey(p => new {  p.TenantId, p.OtherClassId});

Without the OtherClass reference in SpecialOrder I can create objects freely without problems (including SpecialOrder, SuperSpecialOrder etc).

Anyone have a clue what’s going on? I’m lost here 🙁

Edit
I’ve seen in other questions that people remove the TenantId from tables, this is not an option since primary keys are not unique across tenants and we want to keep the shared data architecture.

I know the workaround is having a second TenantId in the SpecialOrder class, but this does not seem logical to me.

  • 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-10T09:23:16+00:00Added an answer on June 10, 2026 at 9:23 am

    Are you trying to do a TPT, where there’s a separate table for Order/Tenant? If so, I think the other poster is correct, and there’s a bug in EF.

    If customers/products are your based mapped classes, this might work for you.

    What happened to me when I created your database is it tried to map the abstract Order class.

    By adding:

    modelBuilder.Ignore<Order>();
    

    The builder kept the mapped properties due to the MapInheritedProperties, but didn’t create the table so that all the FK’s were correctly created.

    I’m assuming you wanted separate tables for each of your classes like the related post above, and to not map your abstract table.

    Entire Model:

     public abstract class BindableBase { }
       //base class for all tenant-scoped objects
       public abstract class TenantModelBase : BindableBase
       {
          [Key]
          public virtual int TenantId { get; set; }
       }
    
       public abstract class Order : TenantModelBase
       {
          public Customer Customer { get; set; } //works: mapped using TenantId and CustomerId
          public Product Product { get; set; } //again, works with TenantId and ProductId
          public string ProductId { get; set; }
          public string CustomerId { get; set; }
       }
       public class Customer : TenantModelBase
       {
          [Key]
          public string CustomerId { get; set; }
       }
    
       public class Product : TenantModelBase
       {
          [Key]
          public string ProductId { get; set; }
       }
    
       public class SpecialOrder : Order
       {
          [Key]
          public int SpecialOrderId { get; set; }
          public OtherClass OtherClass { get; set; } //this fails!, see below
          public string OtherClassId { get; set; }
       }
       public class SuperSpecialOrder : SpecialOrder { }
    
       public class OtherClass : TenantModelBase
       {
          public string OtherClassId { get; set; }
          public ICollection<SpecialOrder> SpecialOrders { get; set; }
       }
    
    
    
       public class Model : DbContext
       {
          public DbSet<Customer> Customers { get; set; }
          public DbSet<Product> Products { get; set; }
          public DbSet<SpecialOrder> SpecialOrders { get; set; }
          public DbSet<SuperSpecialOrder> SuperSpecialOrders { get; set; }
    
          public DbSet<OtherClass> OtherClasses { get; set; }
    
          protected override void OnModelCreating( DbModelBuilder modelBuilder )
          {
             modelBuilder.Entity<OtherClass>()
                .HasKey( k => new { k.TenantId, k.OtherClassId } );
    
             modelBuilder.Entity<Customer>()
                .HasKey( k => new { k.TenantId, k.CustomerId } );
    
             modelBuilder.Entity<Product>()
                .HasKey( k => new { k.TenantId, k.ProductId } );
    
    
             modelBuilder.Entity<SpecialOrder>()
                .Map( m =>
                         {
                            m.MapInheritedProperties();
                            m.ToTable( "SpecialOrders" );
                         } );
    
             modelBuilder.Entity<SpecialOrder>().HasKey( k => new { k.TenantId, k.SpecialOrderId } );
    
             modelBuilder.Entity<SuperSpecialOrder>()
              .Map( m =>
              {
                 m.MapInheritedProperties();
                 m.ToTable( "SuperSpecialOrders" );
              } )
              .HasKey( k => new { k.TenantId, k.SpecialOrderId } );
    
             modelBuilder.Entity<SpecialOrder>()
              .HasRequired( p => p.OtherClass )
              .WithMany( o => o.SpecialOrders )
              .HasForeignKey( p => new { p.TenantId, p.OtherClassId } );
    
             modelBuilder.Entity<Order>()
                .HasRequired( o => o.Customer )
                .WithMany()
                .HasForeignKey( k => new { k.TenantId, k.CustomerId } );
    
             modelBuilder.Entity<Order>()
              .HasRequired( o => o.Product )
              .WithMany()
              .HasForeignKey( k => new { k.TenantId, k.ProductId } );
    
             modelBuilder.Ignore<Order>();
    
    
          }
       }
    

    Created Database:
    enter image description here

    Hope this helps.

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

Sidebar

Related Questions

I have following data structure (simplified): A giant list of the class TestClass public
I have a class structure in C#, similar to the following: [DataContract] class Data
I have the following data structure: P_ID EVSSMIN EVSSMAX TDMIN TDMAX WARD SYRINGE_ID COMBINE_WITH
I have the following data structure (an atomic vector?) output from daply in plyr
I have the following JavaScript data structure. a[] is an array with text strings
I have the following data set structure: date time_in_hours price Sep 03 08 9.76
I have something like the following data structure: Category StartDateTime EndDateTime =============================================== 1 12/1/2009
I have an odd linq subquery issue. Given the following data structure: Parents Children
I have the following casting problem when my data structure sSpecificData contains a field
Let's assume I have the following file structure: data.py foo = [] bar =

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.