Note that there are some explanatory texts on larger screens.

plurals
  1. POTable per Concrete Type (TPC) Mapping in EF4.4
    primarykey
    data
    text
    <p>I'm trying to achieve a TPC design on EF 4.4.</p> <p>I have a set of classes that are already mapped to existing tables, and adding a new set with the same structure, that are to be mapped to different tables, with disjoint IDs.</p> <p>So here's pretty much the new design for the old classes (without the new type of hierarchy that I'm going to add).</p> <pre><code>public abstract class HierarchyLevel { public virtual int Id { get; set; } public string Name { get; set; } } public class MainHierarchyLevel : HierarchyLevel { } public abstract class HierarchyItem { public int Id { get; set; } public string Name { get; set; } public string Description { get; set; } public virtual HierarchyLevel Level { get; set; } } public class MainHierarchyItem : HierarchyItem { } public abstract class HierarchyTreeItem { public int Id { get; set; } public virtual HierarchyTreeItem ParentTreeItem { get; set; } public virtual HierarchyItem Parent { get; set; } public virtual HierarchyItem Child { get; set; } } public class MainHierarchyTreeItem : HierarchyTreeItem { } </code></pre> <p>No matter what I do with the configuration, EF always makes a table name up, e.g. I get a query like</p> <pre><code>SELECT [Extent1].[Id] AS [Id], '0X0X' AS [C1], [Extent2].[Name] AS [Name], [Extent2].[Description] AS [Description], [Extent2].[Level_Id] AS [Level_Id] FROM [dbo].[HierarchyItems] AS [Extent1] INNER JOIN [dbo].[HierarchyItems1] AS [Extent2] ON [Extent1].[Id] = [Extent2].[Id] </code></pre> <p>Where HierarchyItems1 is made up by EF.</p> <p>Here's an example of what i'm doing with the configuration:</p> <pre><code>public class HierarchyItemsConfiguration : EntityTypeConfiguration&lt;HierarchyItem&gt; { public HierarchyItemsConfiguration() { Property(hierarchyItem =&gt; hierarchyItem.Id).HasColumnName("Id").IsRequired(); Property(hierarchyItem =&gt; hierarchyItem.Name).HasColumnName("Name").IsRequired(); Property(hierarchyItem =&gt; hierarchyItem.Description).HasColumnName("Description").IsOptional(); } } public class MainHierarchyItemsConfiguration : EntityTypeConfiguration&lt;MainHierarchyItem&gt; { public MainHierarchyItemsConfiguration() { Map(mb =&gt; { mb.MapInheritedProperties(); mb.ToTable("HierarchyItems"); }); ToTable("HierarchyItems"); HasKey(hierarchyItem =&gt; hierarchyItem.Id); HasRequired(hierarchyItem =&gt; hierarchyItem.Level).WithMany().Map(e =&gt; e.MapKey("Level_Id")); } } </code></pre> <p><strong>Any ideas on how to configure this correctly?</strong></p> <p>Thank you!</p>
    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. 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