Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Change your config like this:</p> <pre><code>public class MainHierarchyLevelConfiguration : EntityTypeConfiguration&lt;MainHierarchyLevel&gt; { public MainHierarchyLevelConfiguration() { Map(mb =&gt; { mb.MapInheritedProperties(); mb.ToTable("MainHierarchyLevels"); }); } } public class MainHierarchyItemsConfiguration : EntityTypeConfiguration&lt;MainHierarchyItem&gt; { public MainHierarchyItemsConfiguration() { Map(mb =&gt; { mb.MapInheritedProperties(); mb.ToTable("MainHierarchyItems"); }); HasKey(hierarchyItem =&gt; hierarchyItem.Id); HasRequired(hierarchyItem =&gt; hierarchyItem.Level).WithMany().Map(e =&gt; e.MapKey("Level_Id")); } } public class HierarchyContext : DbContext { public DbSet&lt;MainHierarchyLevel&gt; MainHierarchyLevels { get; set; } public DbSet&lt;MainHierarchyItem&gt; MainHierarchyItems { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Configurations.Add(new MainHierarchyLevelConfiguration()); modelBuilder.Configurations.Add(new MainHierarchyItemsConfiguration()); } } </code></pre> <p>When running the following test program, 2 tables will be created - one for each of the two concrete classes MainHierarchyLevel and MainHierarchyItem.</p> <pre><code>using (var db = new HierarchyContext()) { var level = new MainHierarchyLevel { Name = "Level1" }; level = db.MainHierarchyLevels.Add(level); var mh = new MainHierarchyItem { Name = "m1", Description = "m1 desc", Level = level }; db.MainHierarchyItems.Add(mh); db.SaveChanges(); var query = from m in db.MainHierarchyItems orderby m.Name select m; Console.WriteLine("All mains in the database:"); foreach (var item in query) { Console.WriteLine(item.Name); } Console.WriteLine("Press any key to exit..."); Console.ReadKey(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload