Note that there are some explanatory texts on larger screens.

plurals
  1. POEntity Framework Code First Mapping Issue
    primarykey
    data
    text
    <p>I am trying to create a model on an existing database.</p> <p>I currently have the following entity mappings:</p> <pre><code>public class TripDriverMap : EntityTypeConfiguration&lt;TripDriver&gt; { public TripDriverMap() { // Primary Key this.HasKey(t =&gt; t.TripDriverMapID); // Properties // Table &amp; Column Mappings this.ToTable("slx_TripDriverMap"); this.Property(t =&gt; t.TripDriverMapID).HasColumnName("TripDriverMapID"); ... this.Property(t =&gt; t.DriverID).HasColumnName("EntityID"); // Relationships ... this.HasRequired(t =&gt; t.Driver) .WithMany(t =&gt; t.TripDrivers) .HasForeignKey(d =&gt; d.DriverID); ... } } public class DriverMap : EntityTypeConfiguration&lt;Driver&gt; { public DriverMap() { // Primary Key this.HasKey(t =&gt; t.ID); ... this.Property(t =&gt; t.ID) .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None); this.Property(t =&gt; t.OwnerEntityID) .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None); // Table &amp; Column Mappings this.ToTable("slx_vw_Drivers"); ... this.Property(t =&gt; t.ID).HasColumnName("EntityID"); ... } } </code></pre> <p>If you look closely I have a column called <strong>EntityID</strong> which I have mapped to the property <strong>DriverID</strong>. Whenever I try to include related entities from either side I get the following error:</p> <p>Invalid column name 'EntityPerson_EntityPersonID'.</p> <p>This is caused because part of the SQL being generated is as follows:</p> <pre><code>[Extent1].[EntityPerson_EntityPersonID] AS [EntityPerson_EntityPersonID] FROM [dbo].[slx_TripDriverMap] AS [Extent1] INNER JOIN [dbo].[slx_vw_Drivers] AS [Extent2] ON [Extent1].[EntityID] = [Extent2].[EntityID] </code></pre> <p>As you can see it is looking for a column called <strong>EntityPerson_EntityPersonID</strong> which doesn't exist. <strong>It does join on the correct columns</strong></p> <p>I cannot rename the column in the TripDriverMap table as it is in use in far to many places, both in the database, the application, and reports.</p> <p>How can I get this to work? I've done all that I thought I had to do in the <strong>TripDriverMap</strong> mapping definition</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.
    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