Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TransactionScope for EFUtilities #43

Closed
Manish176837 opened this issue May 20, 2015 · 3 comments
Closed

TransactionScope for EFUtilities #43

Manish176837 opened this issue May 20, 2015 · 3 comments

Comments

@Manish176837
Copy link

I am using EF.Utilities 0.5.0 in my code and have some query regarding it.
First of all, this is the best package that I have come across for performing bulk operations.
Now about my query, I have a condition in my code where I am trying to delete an entire table (around 24K records) and then add same number of records again.
For deletion, I have added following code:
EFBatchOperation.For(context, context.ArticleImages).Where(x => true).Delete();
And for insertion, I am using following code:
EFBatchOperation.For(context, context.ArticleImages).InsertAll(articleImages);

I am doing this in a single method and passing same context object in both calls.
Now, I want to include these both operations in a single TransactioScope. Please suggest how should I do it?
Thanks in advance.

@MikaelEliasson
Copy link
Owner

First of all I would suggest you to actually test that the following works by throwing an exception between the calls and make sure nothing was deleted. I find Transaction support slightly hard to test.

Basically you should only need to wrap the whole block in a TransactionScope. See the example here: #26

@Manish176837
Copy link
Author

Hi Mikael,
Thanks for the instant reply.
I actually tried doing that but got exception saying "User transactions not supported by EF".
This is the link that was given in the message of the exception: https://msdn.microsoft.com/en-us/data/dn307226.

@Manish176837
Copy link
Author

Hi Mikael,

I am able to set the transaction scope for my code now.
Actually, the solution was given in the same link that I shared above. All I had to do is suspend the retrying execution strategy for my code. I followed the steps and added the same flow(created new TransactionScope object --> Created context --> used EFUtilities functionality).
This is now working perfectly.
Thanks for your help :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants