title: Automatic persistence of state with MassTransit 4.0 saga with EntityFramework Core
body: <p>Hi I've just started using MassTransit 4.0 with .net core and EntityFramework Core.</p>
  
  <p>I have defined a state spanning several classes, which I have wired up in a 1-many relationship using </p>
  
  <pre><code>public class SagaInstanceMap3 : IEntityTypeConfiguration&lt;InstanceState&gt;
  {
      public void Configure(EntityTypeBuilder&lt;InstanceState&gt; builder)
      {
          builder.HasKey(x =&gt; x.CorrelationId);
          builder.HasMany(x =&gt; x.Args);
          builder.HasMany(x =&gt; x.MoreArgs);
          builder.Property(x =&gt; x.RowVersion).IsRowVersion().IsRequired(); 
      }
  }
  </code></pre>
  
  <p>When creating an initial state everything is stored in the DB, but when fetching state in the following transition, <em>only the main table is fetched</em>.</p>
  
  <p>I've been able to remedy this using <code>queryCustomization</code> as seen below</p>
  
  <pre><code>   public static void Main()
      {
          var saga = new MySaga();
  
          var contextFactory = new SagaWithDependencyContextFactory();
  
          using (var context = contextFactory.CreateDbContext(Array.Empty&lt;string&gt;()))
          {
              context.Database.Migrate();
          }
  
          Func&lt;DbContext&gt; sagaDbContextFactory = () =&gt; contextFactory.CreateDbContext(Array.Empty&lt;string&gt;());
  
          var efSagaRepository =
              new EntityFrameworkSagaRepository&lt;InstanceState&gt;(sagaDbContextFactory,
                  queryCustomization: q =&gt; q.Include(it =&gt; it.Args).ThenInclude(it =&gt; it.MoreArgs),
                  optimistic: true); 
  </code></pre>
  
  <p>Unfortunately, this means that I have to remember to map all my relations twice! Is there at way to have the EF Core integration eagerly fetch all child tables upon transitions?</p>
  
  <p>The EF6.0 integration with previous releases of MassTransit did not require me to do the <code>queryCustomization</code> trick.</p>