2009-08-12 5 views
1

Spring.Net이 Linq2SQL에 대한 지원 기능을 내장하고 있는지 여부를 알 수 있습니까? 누군가 Spring.Net 포럼에 NHibernate에 대한 다리가 언급했다. 그러나, 나는 NHibernate를 전혀 사용하지 않을 수도있다. Linq2Sql에 대한 직접적인 지원을 찾고 있습니다.Linq2SQL 용 Spring.Net 지원

TxScopeTransactionManager을 사용하고 있으며 두 개의 linq2sql 호출이 포함 된 비즈니스 메소드에 속성 기반 트랜잭션을 적용하는 경우 트랜잭션이 로컬 트랜잭션이되거나 분산 트랜잭션으로 에스컬레이트됩니까?

답변

2

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을 구성 할 수 있습니다.

+0

멋진 답변,이 주제에 대한 [블로그 게시물] (http://mkarczewski.wordpress.com/2012/09/13/spring-net-linq-to-sql-transactions-support/) 읽기가 너무 마음에 들었습니다. . – Marijn