title: CQRS/ES Projection replay with EF Core
body: <p>I am using EF core as an ORM to which my ES events get played onto for the read-side of my CQRS application.</p>
  
  <p>I have created a new feature that requires some modification of projections, and how they are represented. I wish to discard the current read model, and re-project the stream to rebuild the model.</p>
  
  <p>The performance has been poor, as every time I create a new context, and persist it, looping over the events;</p>
  
  <pre class="lang-cs prettyprint-override"><code>foreach (var event in events)
  {
      using (var scope = _container.BeginScope('projection-scope'))
      using (var dbContext = scope.Resolve&lt;MyDbContext&gt;())
      {
          await scope.Resolve&lt;IMediator&gt;().Publish(event);
          await context.SaveChangesAsync();
      }
  }
  </code></pre>
  
  <p>I am using DI containers to keep the persistance call out of the handler in an attempt to batch the projections and help improve performance, but am coming across increasing difficulty, with attached entities, relationships, and other SQL problems.</p>
  
  <p>Is this a sound strategy, to bulk up multiple operations in an EF context, or is it better to ditch the ORM and go for a direct-SQL approach (maybe using dapper)?</p>