ConnectionUtils
및 그 GetConnectionTxPair
메서드를 사용하는 것이 좋습니다. 데이터베이스 연결 쌍과 연결된 트랜잭션을 반환합니다. 트랜잭션에 대한 참조가있는 경우이 컨텍스트의 속성을 Transaction
으로 설정하여 명시 적으로 LINQ2SQL DataContext
을 등록 할 수 있습니다.
당신은 AdoTemplate
가 LINQ2SQL을 지원하기 위해 확장 할 수
public delegate T DataContextDelegate<T>(DataContext command);
public class LinqAdoTemplate : AdoTemplate
{
public virtual T Execute<T>(DataContextDelegate<T> del)
{
ConnectionTxPair connTxPair = ConnectionUtils.GetConnectionTxPair(DbProvider);
using (var context = new DataContext(connTxPair.Connection))
{
//downcast is a bit smelly here
//one can throw exception though when connTxPair.Transaction is of invalid type
context.Transaction = connTxPair.Transaction as DbTransaction;
return del(context);
}
}
}
그런 다음 당신은 당신의 AdoTemplate 인식 개체로이를 주입 Spring.NET을 구성 할 수 있습니다.
멋진 답변,이 주제에 대한 [블로그 게시물] (http://mkarczewski.wordpress.com/2012/09/13/spring-net-linq-to-sql-transactions-support/) 읽기가 너무 마음에 들었습니다. . – Marijn