EF 엔티티 모델의 엔티티 집합 인스턴스 사이의 관계를 이해하려고합니다.이 모델은 Entity Designer에서 만들어졌습니다. 기본적으로 엔티티의 Repository 클래스의 2 인스턴스를 갖는 1 논리적 트랜잭션으로 끝납니다. 한 인스턴스에서 성공적으로 커밋 된 데이터 (SQLServer에 대한 직접 SSMS 쿼리로 확인 됨)는 다른 인스턴스에서 볼 수 없게됩니다.MVC 엔티티 프레임 워크가 여러 엔티티 인스턴스에서 동작하는 경우
ARepository _aR = new ARepository();
A a = _aR.Find(id); //Find does something like: return db.ASet.Where(x => x.id == id);
b.BeginAcctBal = a.AcctBal;
brepo.AddTxn(params ... n); //Creates and saves n txns, and creates its own ARepository instance that updates its instance of AcctBal, which I can see happening in the DB)
A a = _aR.Find(id); //The hope is this gets the updated AcctBal after committed by AddTxn, but it doesn't).
b.EndAcctBal = a.AcctBal; // Still contains the starting balance value.
지금은 그 이후의 코드가 실제로 후 AddTxn AcctBal 값을 얻을 않습니다 즉시 AddTxn 후 ARepository _aR = new ARepository();
을 세우면 다음은 대략 흐름입니다.
질문 :
왜 db.ASet.Where(x => x.id == id);
는 DB에서 다시로드하지 않는 이유는 무엇입니까? _aR 인스턴스가 생성 된 시점의 스냅 샷을 항상 읽는 중입니까?
_aR이 스냅 샷 인 경우 다시로드 할 수있는 방법이 있습니까?
_aR이 스냅 샷 인 경우 트랜잭션 무결성은 어떻게 유지됩니까? 좀 더 구체적으로 말해, 그것을 유지하기 위해 뭔가를해야합니까, 아니면 EF와 MVC 1.0이 나를 위해이 트랜잭션 마법을 사용합니까?