We use entityframework for the readmodels.
public void Handle(IPublishedEvent<AliquotUnpositionedEvent> evnt)
{
var payload = evnt.Payload;
Handle(context =>
{
var aliquot = context.ClaimedAliquotPositionsReadModels.SingleOrDefault(a => a.AliquotId == payload.AliquotId);
if (aliquot == null) return;
aliquot.BoxId = Guid.Empty;
aliquot.Position = -1;
aliquot.Positioned = false;
aliquot.BoxName = string.Empty;
});
}
protected virtual void Handle(Action<WebsiteReadModelContext> handler)
{
try
{
using (var context = new WebsiteReadModelContext())
{
handler(context);
context.SaveChanges();
}
}
catch (DbUpdateException)
{
Handle(handler);
}
}
What you are trying to tell me is I should do the context.SaveChanges() not per event, but per batch of events. Am I right? However that needs me to do a structural refactor. I need to provide a EF Context to each denormalizer and call the savechanges somewhere else... Where would be the best place to do the savechanges? At the moment each event gets saved in the eventhandler in the denormalizer. However when I am going to use this context at higher level I will also need it to query so I need to provide it also to my repositories, because not everything is persisted immediately. What would be the best strategy to manage this context?
Hope you can help me out with this Greg. This will probably improve our overall performance... However the impact would be high I think in order to get this working and test it.
On Monday, July 30, 2012 3:36:12 PM UTC+2, Greg Young wrote: