public void WithBidiManyToOne() { using (ISession session = OpenSession()) using (var trx = session.BeginTransaction()) { var father = new PersonM2O(); var mother = new PersonM2O(); var son = new PersonM2O(); var daughter = new PersonM2O(); var home = new AddressM2O(); var office = new AddressM2O(); home.AddPerson(father); home.AddPerson(mother); home.AddPerson(son); home.AddPerson(daughter); office.AddPerson(father); office.AddPerson(mother); session.Save(home); session.Save(office); Assert.DoesNotThrow(() => { trx.Commit(); }); } // 2 Address inserts, 4 Person inserts, 2 Person.Address updates Assert.AreEqual(3, StatsBatcher.BatchSizes.Count, "Unexpected batches count"); Assert.AreEqual(8, StatsBatcher.BatchSizes.Sum(), "Unexpected batched queries count"); }
public async System.Threading.Tasks.Task WithBidiManyToOneAsync() { using (ISession session = OpenSession()) using (var trx = session.BeginTransaction()) { var father = new PersonM2O(); var mother = new PersonM2O(); var son = new PersonM2O(); var daughter = new PersonM2O(); var home = new AddressM2O(); var office = new AddressM2O(); home.AddPerson(father); home.AddPerson(mother); home.AddPerson(son); home.AddPerson(daughter); office.AddPerson(father); office.AddPerson(mother); await(session.SaveAsync(home)); await(session.SaveAsync(office)); Assert.DoesNotThrowAsync(() => { return(trx.CommitAsync()); }); } // 2 Address inserts, 4 Person inserts, 2 Person.Address updates Assert.AreEqual(3, StatsBatcher.BatchSizes.Count, "Unexpected batches count"); Assert.AreEqual(8, StatsBatcher.BatchSizes.Sum(), "Unexpected batched queries count"); }
public virtual void AddPerson(PersonM2O person) { Persons.Add(person); person.Address = this; }