asp.net - Will transactionscope work over multiple calls to different services? -


I am writing some merge functionality in C # asp.NET MVC2. I am also using Linq2SQL.

I have a block of code that calls two services, messaging and user service. Both of these words are called their proper treasure and amend the DB. Each repository has declared its own example of the repository, so I am thinking that this code will increase the code, the code is called from the account service, is it going to work at this level? And is it also bad practice to declare DataContext at the top of every repository or should I pass the object in any way? Thank you in advance

using {TransactionScope scope = new TransactionScope ()) {try for merge} {// update if user for primary user ownership (! _MessageService .UpdateCreatedById (MergeUser .UserID, CoreUser.UserID)) {return false; } // Update user can be managed by the primary user foreach (_MessageService.GetUserComments (MergeUser.UserID)) var curMomment {curComment.CreatedBy = CoreUser.UserID; } _MessageService.Save (); // Update login to be owned by the primary user foreach (_UserService.GetLogins (MergeUser.UserID) var CurLogin) {CurLogin.UserID = CoreUser.UserID; } _UserService.Save (); Scope.Complete (); } Back true; } Hold (Exception Pre) {_ErrorStack.Add (ex.Message); ErrorService.AddError (new errorModel ("Portal", "WidgetRepository", ErrorHelper.ErrorTypes.Critical, ex)); return false; }

Yes, this will work TransactionScope Distributed Transaction Coordinator , So it is capable of hosting transactions beyond the level of the database.

The recommended practice for data-tactical lifecycle is to limit it to the work of an entity.


Comments