저는 지난 몇 시간 동안 인터넷 검색을 해왔지만 답변을 찾지 못했기 때문에 여기 누군가가 올바른 방향으로 나를 안내 할 수 있기를 바랍니다.TransactionScope, EF DbContext 및 Dirty Read
TransactionScope 내에서 EF DbContext (코드 우선)로 더티 읽기를 수행하는 방법을 알고 싶습니다.
using(TransactionScope scope2 = new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions{IsolationLEvel = IsolationLevel.ReadUncommitted}))
{
var objects = context.SomeTable.Where(...).Select(...); //times out here on the
}
적절한 방법은 무엇입니까 : 예
DbContext context = new MyEntities();
using(TransactionScope scope = new TransactionScope())
{
context.SomeTable.Add(someObject);
context.SaveChanges();
var objects = context.SomeTable.Where(...).Select(...); //times out here on the read, because the write above locks the tables
//modify each object
context.SaveChanges();
scope.Complete(); //transaction is a success only if the entire batch succeeds
}
위해 나는 다음과 읽기 호출을 래핑 시도?
무슨 RDMS를 사용합니까? 일반적으로 작성자는 SQLServer가 아니면 독자를 차단해서는 안됩니다. 그러나 SQLServer의 경우에도 더티 읽기를 사용하는 것보다 나은 해결책이 있습니다. 데이터베이스에 대해 READ_COMMITTED_SNAPSHOT을 활성화 할 수 있습니다. – a1ex07
삽입 된 개체의 ID를 잡는 것처럼 보입니다. 삽입 한 후에 개체를 선택하는 것보다 쉬운 방법이 있습니다. 이 경우인가요? – SmartK8
"읽기 시간이 여기에 있습니다. 왜냐하면 위의 쓰기가 테이블을 잠급니다. 왜냐하면 읽기가 동일한 트랜잭션에서 발생하기 때문입니다. 트란이 왜 스스로를 막을까요? 또한, 쓰기는 전체 테이블 (신화)을 잠그지 않습니다. – usr