Note that there are some explanatory texts on larger screens.

plurals
  1. POEF: TPH implementation with Fluent mapping throws Invalid Column Name exception
    primarykey
    data
    text
    <p>Here is my implementation.</p> <pre><code> public partial class Person { #region Constructors public Person() { PersonExpirableCredentials = new List&lt;personexpirablecredential&gt;(); } #endregion Constructors #region Properties public int PersonID { get; protected set; } public virtual ICollection&lt;personexpirablecredential&gt; PersonExpirableCredentials { get; set; } #endregion } public abstract class PersonCredential { #region Constructors public PersonCredential() { } #endregion #region Properties public int PersonID { get; protected set; } public int PersonCredentialID { get; protected set; } public System.DateTime WhenEffective { get; set; } public Nullable&lt;system.datetime&gt; WhenExpire { get; set; } public virtual Person Person { get; set; } } public partial class PersonExpirableCredential : PersonCredential { #region Constructors public PersonExpirableCredential() : base() { } #endregion #region Properties public DateTime? WhenCompleted { get; set; } public string CredentialNumber { get; set; } #endregion } </code></pre> <p>Below are the fluent mappings </p> <pre><code>internal partial class PersonMapping : EntityTypeConfiguration&lt;person&gt; { #region Constructors public PersonMapping() { this.HasKey(t =&gt; t.PersonID); this.ToTable("Person"); } #endregion } internal partial class PersonCredentialMapping : EntityTypeConfiguration&lt;personcredential&gt; { #region Constructors public PersonCredentialMapping() { this.HasKey(t =&gt; new { t.PersonCredentialID }); this.ToTable("PersonCredential"); this.HasRequired(t =&gt; t.Person).WithMany().HasForeignKey(d =&gt; d.PersonID); } #endregion } internal partial class PersonExpirableCredentialMapping : EntityTypeConfiguration&lt;personexpirablecredential&gt; { #region Constructors public PersonExpirableCredentialMapping() { this.Map(m =&gt; { m.Requires("CredentialCategoryCode").HasValue("Expirable"); }); this.ToTable("PersonCredential"); } #endregion } </code></pre> <p>Here is the database model:</p> <p><img src="https://i.stack.imgur.com/arAWd.jpg" alt="TPH Diagram"></p> <p>Now in my data access layer, when i retrieve the person and try to do access "Person.PersonExpirableCredentials". It throws an error with Invalid Column Name "Person_PersonID". Below is the SQL query, it generates.</p> <pre><code>exec sp_executesql N'SELECT [Extent1].[PersonID] AS [PersonID], ''1X0X'' AS [C1], [Extent1].[PersonCredentialID] AS [PersonCredentialID], [Extent1].[WhenEffective] AS [WhenEffective], [Extent1].[WhenExpire] AS [WhenExpire], [Extent1].[WhenCompleted] AS [WhenCompleted], [Extent1].[CredentialNumber] AS [CredentialNumber], [Extent1].[Person_PersonID] AS [Person_PersonID] FROM [dbo].[PersonCredential] AS [Extent1] WHERE ([Extent1].[Person_PersonID] IS NOT NULL) AND ([Extent1].[Person_PersonID] = @EntityKeyValue1) AND ([Extent1].[CredentialCategoryCode] = ''Expirable'')',N'@EntityKeyValue1 int',@EntityKeyValue1=3 </code></pre> <p>For some reason, EF is not able to identify the relationship between the Person Class and the subclass PersonExpirableCredentials. </p> <p>Help Please.</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    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