SharpRepository / SharpRepository

C# Generic Repository for use with Entity Framework, RavenDB and more with built-in caching options.
Other
658 stars 169 forks source link

Make Batching more general - allow for calls to multiple repositories #101

Open jtreuting opened 10 years ago

jtreuting commented 10 years ago

Batching right now is restricted to a single repository. It would be much more useful if it could be used to do a batch where you add a member to the MemberRepository and delete an order form the OrderRepository and make sure they both are batched together.

bgriswold commented 10 years ago

That's a really great idea. Surprising this hasn't come up before.

On Nov 26, 2013, at 11:25 AM, Jeff Treuting notifications@github.com wrote:

Batching right now is restricted to a single repository. It would be much more useful if it could be used to do a batch where you add a member to the MemberRepository and delete an order form the OrderRepository and make sure they both are batched together.

— Reply to this email directly or view it on GitHub.

johnkattenhorn commented 10 years ago

This is one of the major blockers (along with the where's the UOW question) when I suggest SharpRepository to clients / colleagues. Any thought's on a potential implementation and maybe I could help out ?

jtreuting commented 10 years ago

Haven't had a chance to really think it through yet unfortunately. I'd love to have some help. If you have any thoughts on implementation I'm all ears. Otherwise I'll hopefully get some time soon to think on it and post my thoughts here.

Sent via my phone so please excuse my typos and brevity

-------- Original message -------- From: johnkattenhorn notifications@github.com Date: 01/04/2014 5:44 AM (GMT-08:00) To: SharpRepository/SharpRepository SharpRepository@noreply.github.com Cc: Jeff Treuting jtreuting@fairwaytech.com Subject: Re: [SharpRepository] Make Batching more general - allow for calls to multiple repositories (#101)

This is one of the major blockers (along with the where's the UOW question) when I suggest SharpRepository to clients / colleagues. Any thought's on a potential implementation and maybe I could help out ?

Reply to this email directly or view it on GitHubhttps://github.com/SharpRepository/SharpRepository/issues/101#issuecomment-31578636.

johnkattenhorn commented 10 years ago

Hi Jeff,

I’ll give it some thought next week and I’ll run any implementation ideas pass this post before I do anything.

All the best.

John

From: Jeff Treuting [mailto:notifications@github.com] Sent: 04 January 2014 21:39 To: SharpRepository/SharpRepository Cc: John Kattenhorn Subject: Re: [SharpRepository] Make Batching more general - allow for calls to multiple repositories (#101)

Haven't had a chance to really think it through yet unfortunately. I'd love to have some help. If you have any thoughts on implementation I'm all ears. Otherwise I'll hopefully get some time soon to think on it and post my thoughts here.

Sent via my phone so please excuse my typos and brevity

-------- Original message -------- From: johnkattenhorn notifications@github.com<mailto:notifications@github.com> Date: 01/04/2014 5:44 AM (GMT-08:00) To: SharpRepository/SharpRepository SharpRepository@noreply.github.com<mailto:SharpRepository@noreply.github.com> Cc: Jeff Treuting jtreuting@fairwaytech.com<mailto:jtreuting@fairwaytech.com> Subject: Re: [SharpRepository] Make Batching more general - allow for calls to multiple repositories (#101)

This is one of the major blockers (along with the where's the UOW question) when I suggest SharpRepository to clients / colleagues. Any thought's on a potential implementation and maybe I could help out ?

Reply to this email directly or view it on GitHubhttps://github.com/SharpRepository/SharpRepository/issues/101#issuecomment-31578636.

— Reply to this email directly or view it on GitHubhttps://github.com/SharpRepository/SharpRepository/issues/101#issuecomment-31589323.

jtreuting commented 10 years ago

The one thought I've had recently is that as part of this refactor it would be nice if the consumer could do something like this (think TransactionScope):

using (var batch = _repository.BeginBatch())
{
    _repository.Add(entity); // instead of batch.Add(entity)

    batch.Commit();
}

This just seems more natural. In order to pull this out and make it available to go across multiple repositories the _repository.BeginBatch() will probably need to change to a static like RepositoryBatch.Begin().

craigmaslowski commented 10 years ago

Jeff, here's the code to implement generic batching using TranscactionScope, as we talked about, including some tests passing tests.

Let me know what you think, and if you see any potential gotchas with the changes. I wouldn't be surprised if I missed some use case. If things look good though, I'll submit another pull request.

johnkattenhorn commented 10 years ago

Hey Craig,

I've finally freed up sometime and I'm really interested in the work you've done so I'm going to pull it today and hook your branch an application of mine which would we couldn't easily use standard sharprepository and see how it goes. Thanks for work dude.

Appreciated.

John

craigmaslowski commented 10 years ago

Thanks, John. Jeff hasn't pulled it yet because we thought there might be some problems in certain use cases, which I can't remember exactly now. My guess is that it might not quite be ready for primetime, so please let us know how it goes.

Ian1971 commented 9 years ago

Coming to this somewhat late, but I've got around this for EF6 by wrapping DbContextTransaction and injecting DbContext into my wrapper class.

dannief commented 8 years ago

@Ian1971 Do you have any sample code?