title: Having issues with a dependent property in a referential restraint
body: <p>I keep getting this error when I try to submit to the database:</p>
  
  <blockquote>
    <p>A dependent property in a ReferentialConstraint is mapped to a store-generated column. Column: 'NPPRProvId'</p>
  </blockquote>
  
  <p>Here's where it breaks:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public static bool Save(NPPR_Provider provider, State state, string filename, bool validateBeforeSave = true )
  {
      using (var db = new NPPRContext(state))
      {
          var prov = new NPPR_Provider()
          {
              First = provider.First,
              Middle = provider.Middle,
              Last = provider.Last,
              DateOfBirth = provider.DateOfBirth,
              DateOfDeath = provider.DateOfDeath,
              Gender = provider.Gender,
              SSN = provider.SSN,
              DegreeCode = provider.DegreeCode,
              BusinessName = provider.BusinessName,
              DbaName = provider.DbaName,
              Action = "A",
              EffectiveDate = "20121212",
              EndDate = "99991231",
  
              NPPR_ServLocation = new NPPR_ServLocation()
              {
                  EnrollmentType = provider.NPPR_ServLocation.EnrollmentType,
                  OrganizationType = provider.NPPR_ServLocation.OrganizationType,
                  ProviderTypeCode = provider.NPPR_ServLocation.ProviderTypeCode,
                  IRSTaxAssociations = provider.NPPR_ServLocation.IRSTaxAssociations,
                  NPIAssociations = provider.NPPR_ServLocation.NPIAssociations,
                  Address = provider.NPPR_ServLocation.Address
              },
              NPPR_Header = new NPPR_Header()
              {
                  FileName = filename,
                  TransactionDate = Utilities.DateTimeToPRNDate(DateTime.Now),
                  FileLoadDate = DateTime.Now,
                  SubmitterId = "M00000503",
                  Purpose = "A",
                  Action = "A"
              }
          };
          foreach(var npi in prov.NPPR_ServLocation.NPIAssociations)
          {
              npi.NPIType = prov.NPPR_ServLocation.OrganizationType == "I" ? "1" : "2";
          }
  
          prov.NPPR_ServLocation.Licenses = SegmentOrNull&lt;NPPR_Licenses&gt;(provider.NPPR_ServLocation, "Licenses", "LicenseNumber");
          prov.NPPR_ServLocation.Certifications = SegmentOrNull&lt;NPPR_Certifications&gt;(provider.NPPR_ServLocation, "Certifications", "CertificationNumber");
          prov.NPPR_ServLocation.Specialties = SegmentOrNull&lt;NPPR_Specialties&gt;(provider.NPPR_ServLocation, "Specialties", "SpecialtyCode");
          prov.NPPR_ServLocation.Taxonomies = SegmentOrNull&lt;NPPR_Taxonomies&gt;(provider.NPPR_ServLocation, "Taxonomies", "TaxonomyCode");
          prov.NPPR_ServLocation.OtherIds = SegmentOrNull&lt;NPPR_OtherIds&gt;(provider.NPPR_ServLocation, "OtherIds", "IdentifierTypeId");
          prov.NPPR_ServLocation.GroupAssociations = SegmentOrNull&lt;NPPR_GroupAssociations&gt;(provider.NPPR_ServLocation, "GroupAssociations", "ProviderLocationId");
          db.NPPR_Provider.Add(prov);
          if (validateBeforeSave)
              db.SaveChangesWithValidation();
          else
              db.SaveChanges();
          return true;
      }
  }
  </code></pre>
  
  <p><code>db.SaveChanges()</code> is where, according to the stacktrace, the exception is thrown.  This function was originally written for EF Core, but due to issues with the server, I was forced to turn everything to EF6.4.  Under Core, this method worked fine, but under EF6, it throws an exception.  I've tried a few things I've read on other SO questions but so far no luck.</p>
  
  <p>Specifically the exception throws on the NPPR_Provider primary key, <code>NPPRProvId</code>, which at no point in my code is ever read or written, except to be defined in the model.</p>
  
  <p>In SQL, the NPPRProvId is <code>PK, int, not null</code></p>
  
  <p>The model involved:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class NPPR_Provider : Provider
  {
      [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public int NPPRProvId { get; set; }
  
      //[ForeignKey("NPPR_Header")]
      public int? NPPRFileId { get; set; }
  
      [ForeignKey("NPPRFileId")]
      public NPPR_Header NPPR_Header { get; set; }
  
      [ForeignKey("NPPRProvId")]
      public NPPR_ServLocation NPPR_ServLocation { get; set; }
  }
  </code></pre>
  
  <p>What am I doing wrong here and how might I fix it?  I'm still fairly new to EF and this is my first major project in EF and MVC, and in the .NET framework in general.</p>