関数に SqlConnection を渡しています。各関数で複数のオブジェクト コンテキストが作成されます。分散トランザクション サービスをオンにすることなく、単一のトランザクション スコープで使用できるように、すべてのオブジェクト コンテキストに渡した単一の SqlConnection を使用したいと考えています。
サンプルコードは次のとおりです。
public bool InsertObjects<T>(TransactionScope transaction, SqlConnection sqlConnection, IEnumerable<T> objectsToInsert)
{
using (EntityConnection conn = GetEntityConnection())
{
Type objectContextType;
ObjectContext objectContext = (ObjectContext) Activator.CreateInstance(objectContextType, new object[] {conn});
//Some code using the objectContext
}
}