private static void AddMemberRoots(IDynamicRepository repository, AggregateRootDefine define, DynamicRoot root) { var memberRoots = root.GetRoots(); foreach (var member in memberRoots) { var id = member.GetIdentity(); //为了防止死锁,我们开启的是不带锁的模式判定是否有本地数据 //虽然这有可能造成重复输入的插入而导致报错,但是几率非常低,而且不会引起灾难性bug var local = repository.Find(define, id, QueryLevel.None); if (local.IsEmpty()) { repository.Add(define, member); } } }