public void StatelessSession() { var a = new FormPartA(); ActiveRecordMediator<FormPartA>.Create(a); using (var session = ActiveRecordMediator.GetSessionFactoryHolder().GetSessionFactory(typeof (object)).OpenStatelessSession()) { var entityA = new Form(); entityA.PartA = session.Get<FormPartA>(a.Id); session.Insert(entityA); } }
public void Null() { var a = new Form(); ActiveRecordMediator.Create(a); ActiveRecordMediator<Form>.FindAll(EqOrNull("Name", null)); }
public void IsTransient() { var aform = new Form(); var pk = ActiveRecordModel.GetModel(typeof(Form)).PrimaryKey; var unsavedValue = pk.PrimaryKeyAtt.UnsavedValue; var convertedUnsavedValue = Convert.ChangeType(unsavedValue, pk.Property.PropertyType); var pkValue = pk.Property.GetValue(aform, null); var transient = Equals(convertedUnsavedValue, pkValue); }
public void LazyBelongsTo() { var form = new Form(); var partA = new FormPartA(); ActiveRecordMediator.Create(form); ActiveRecordMediator.Create(partA); form.PartA = partA; ActiveRecordMediator.Update(form); partA.Parent = form; ActiveRecordMediator.Update(partA); var form1 = ActiveRecordMediator<Form>.FindFirst(); Assert.IsFalse(NHibernateUtil.IsInitialized(form1.PartA)); }
public void IsLazy() { var form = new Form(); var partA = new FormPartA(); var partB = new FormPartB(); ActiveRecordMediator.Create(form); ActiveRecordMediator.Create(partA); ActiveRecordMediator.Create(partB); form.PartA = partA; form.PartB = partB; ActiveRecordMediator.Update(form); partA.Parent = form; ActiveRecordMediator.Update(partA); partB.Parent = form; ActiveRecordMediator.Update(partB); LogManager.GetLogger("test").Debug("All objects saved"); var form1 = ActiveRecordMediator<Form>.FindFirst(); Assert.IsTrue(NHibernateUtil.IsInitialized(form1.PartA)); Assert.IsTrue(NHibernateUtil.IsInitialized(form1.PartB)); var partA1 = ActiveRecordMediator<FormPartA>.FindFirst(); Assert.IsFalse(NHibernateUtil.IsInitialized(partA1.Parent)); var partB1 = ActiveRecordMediator<FormPartB>.FindFirst(); Assert.IsFalse(NHibernateUtil.IsInitialized(partB1.Parent)); }