title: Saving data to db with Entity splitting
body: <p>I'm building Reporting system, but having problem with saving data to db (entity splitting). </p>
  
  <p>My Entities:</p>
  
  <pre><code>public class Report
  {
      [Key]
      public int ReportId { get; set; }
      public string Title { get; set; }
      public int? DateRange { get; set; }
      public int Layout { get; set; }
      public DateTime? DateFrom { get; set; }
      public DateTime? DateTo { get; set; }
      public int OwnerId { get; set; }
      public DateTime DateCreated { get; set; }
      public virtual List&lt;ReportCharts&gt; ReportCharts { get; set; }
      public virtual List&lt;ReportElements&gt; ReportElements { get; set; }
  }
  
   public class ReportElements
  {
      [Key, Column(Order = 1)]
      public int ReportId { get; set; }
      [Key, Column(Order = 2)]
      public string ElementName { get; set; }
      public Boolean Active { get; set; }
  }
  
  //Entity class ReportCharts
  public class ReportCharts
  {
      [Key, Column(Order = 1)]
      public int ReportId { get; set; }
      [Key, Column(Order = 2)]
      public string ChartId { get; set; }
      public Boolean Active { get; set; }
  }
  </code></pre>
  
  <p>In my DbContext:</p>
  
  <pre><code>class EFDbContext : DbContext
  {
      public DbSet&lt;Report&gt; Reports { get; set; }
      protected virtual void OnModelCreating(DbModelBuilder modelBuilder)
      {
          modelBuilder.Entity&lt;Report&gt;().Property(t =&gt; t.ReportId).HasColumnName("ReportId");
          modelBuilder.Entity&lt;Report&gt;().Property(t =&gt; t.Title).HasColumnName("Title");
          modelBuilder.Entity&lt;Report&gt;().Property(t =&gt; t.DateRange).HasColumnName("DateRange");
          modelBuilder.Entity&lt;Report&gt;().Property(t =&gt; t.Layout).HasColumnName("Layout");
          modelBuilder.Entity&lt;Report&gt;().Property(t =&gt; t.DateFrom).HasColumnName("DateFrom");
          modelBuilder.Entity&lt;Report&gt;().Property(t =&gt; t.DateTo).HasColumnName("DateTo");
          modelBuilder.Entity&lt;Report&gt;().Property(t =&gt; t.OwnerId).HasColumnName("OwnerId");
          modelBuilder.Entity&lt;Report&gt;().Property(t =&gt; t.DateCreated).HasColumnName("DateCreated");
          modelBuilder.Entity&lt;Report&gt;().HasMany(t =&gt; t.ReportElements).WithRequired().HasForeignKey(c =&gt; c.ReportId);
          modelBuilder.Entity&lt;Report&gt;().HasMany(t =&gt; t.ReportCharts).WithRequired().HasForeignKey(p =&gt; p.ReportId);
          modelBuilder.Entity&lt;ReportElements&gt;().Property(c =&gt; c.ElementName).HasColumnName("ElementName");
          modelBuilder.Entity&lt;ReportElements&gt;().HasKey(c =&gt; new { c.ReportId, c.ElementName });
          modelBuilder.Entity&lt;ReportCharts&gt;().Property(p =&gt; p.ChartId).HasColumnName("ChartId");
          modelBuilder.Entity&lt;ReportCharts&gt;().HasKey(c =&gt; new { c.ReportId, c.ChartId });
      }
  
  }
  </code></pre>
  
  <p>In EF repository:</p>
  
  <pre><code>    public void Save(Report report)
      {
        assignSettingsToEntity(report);  
          // ????
          context.Reports.Add(report);
          context.SaveChanges();     
      }
  
      //Assign settings to Report Entity  
      public void assignSettingsToEntity(Report report)
      {
          report.Title = report.getSettings().title;
          report.Layout = report.getSettings().layout;
          report.DateRange = report.getSettings().layout;
          report.DateFrom = report.getSettings().dateFrom;
          report.DateTo = report.getSettings().dateTo;
          report.DateCreated = DateTime.Now;
          report.OwnerId = 54180;
      }
  </code></pre>
  
  <p>When I do Save with the above code data is save to Report table only. How can I amend this code to save data to all three tables.</p>
  
  <p>Many thanks for help </p>