digipolisantwerp / dataaccess_aspnetcore_deprecated

Generic repository/unit of work framework for ASP.NET Core with Entity Framework.
Other
140 stars 45 forks source link

Unit Of work Begintransaction #22

Closed coskuncinar closed 7 years ago

coskuncinar commented 7 years ago

I am working to add new feature to UOW, but your framework is a bit complicated. Where should I add Begintransaction and Commit And Rollback. Thank you for responding..

StevenVandenBroeck commented 7 years ago

I would add it to UnitOfWorkBase : https://github.com/digipolisantwerp/dataaccess_aspnetcore/src/Digipolis.DataAccess/Uow/UnitOfWorkBase.cs

coskuncinar commented 7 years ago

this is not enough if you say "SaveChangesAsync' , i need start begintran when i insert /update first record ,think "begin tran commit " as in Tsql ( you need thought to take document last number in DocumentNumberTablo and update last+1 document number in same DocumentNumberTablo)
Will you add this feature? or How can I add you? can you help me??

"I'm sorry my english"

StevenVandenBroeck commented 7 years ago

The SaveChanges methods are transactional. If you prepare all your changes on the DbContext and then call SaveChanges, all changes will be applied in 1 transaction.

If you want to manage the transactions yourself, you can add BeginTransaction, RollBack and Commit methods on UnitOfWorkBase and expose the corresponding methods of the _context.Database object.

coskuncinar commented 7 years ago

yeap , I want to manage the transactions myself. But The SaveChanges is last step. think like that begin tran go declare @DocNum select @DocNum=DocumentNumber from DocumentNumbers DocumentType =xx ---> when i take lastdocumentnumber, nobody can take DocumentNumber in same time . other client should wait . insert into importsTable(DocNum,xx,xxx,xxx) values (@DocNum,yyy,yy,yyy) //other code, insert update and such update s set s.DocumentNumber=@DocNum+1 from DocumentNumbers DocumentType =xx go commit or rollback go when its done , other client can connect to this "DocumentNumbers" table thats why I must manage my process

I hope I can express myself...

StevenVandenBroeck commented 7 years ago

Then I would make a custom repository, handle the whole transaction in there and not use the generic UnitOfWork and repositories.

anhlee24 commented 7 years ago

Can you give an example how to use transaction?

Thank you.

StevenVandenBroeck commented 7 years ago

@anhlee24 , you can find more info on transactions with EF Core here : https://docs.microsoft.com/en-us/ef/core/saving/transactions.

anhlee24 commented 7 years ago

Thank you!

i do not know that they can use together.