开发者

Handling transaction context using method attribute in linq to sql

开发者 https://www.devze.com 2022-12-27 17:10 出处:网络
Is there a way to just put an attribute to a method so that the whole code in the method is executed in a transaction scope? I\'ve seen this done in sharp architecture but I\'m using Linq to sql not n

Is there a way to just put an attribute to a method so that the whole code in the method is executed in a transaction scope? I've seen this done in sharp architecture but I'm using Linq to sql not nhibernate. Thanks!

This what I would like to do:

[Transaction] 
public void InsertCustomer(Customer开发者_如何学C customer)
{ //insert customer }

So that the body of the method executes in a transaction scope.


Which method? If you mean SubmitChanges, then I believe that is already transactional. Otherwise, just spin up your own TransactionScope around what you want controlled, or pass in a configured connection to the DataContext overloaded constructor.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号