//[Ignore("TimeZone Portions commented out - http://jira.nhibernate.org:8080/browse/NH-88")] public void AssociationId() { string id; Bar bar; MoreStuff more; using (ISession s = OpenSession()) { using (ITransaction t = s.BeginTransaction()) { bar = new Bar(); id = (string) s.Save(bar); more = new MoreStuff(); more.Name = "More Stuff"; more.IntId = 12; more.StringId = "id"; Stuff stuf = new Stuff(); stuf.MoreStuff = more; more.Stuffs = new ArrayList(); more.Stuffs.Add(stuf); stuf.Foo = bar; stuf.Id = 1234; s.Save(more); t.Commit(); } } using (ISession s = OpenSession()) { using (ITransaction t = s.BeginTransaction()) { //The special property (lowercase) id may be used to reference the unique identifier of an object. (You may also use its property name.) string hqlString = "from s in class Stuff where s.Foo.id = ? and s.id.Id = ? and s.MoreStuff.id.IntId = ? and s.MoreStuff.id.StringId = ?"; object[] values = new object[] {bar, (long) 1234, 12, "id"}; IType[] types = new IType[] { NHibernateUtil.Entity(typeof(Foo)), NHibernateUtil.Int64, NHibernateUtil.Int32, NHibernateUtil.String }; //IList results = s.List( hqlString, values, types ); IQuery q = s.CreateQuery(hqlString); for (int i = 0; i < values.Length; i++) { q.SetParameter(i, values[i], types[i]); } IList results = q.List(); Assert.AreEqual(1, results.Count); hqlString = "from s in class Stuff where s.Foo.id = ? and s.id.Id = ? and s.MoreStuff.Name = ?"; values = new object[] {bar, (long) 1234, "More Stuff"}; types = new IType[] { NHibernateUtil.Entity(typeof(Foo)), NHibernateUtil.Int64, NHibernateUtil.String }; q = s.CreateQuery(hqlString); for (int i = 0; i < values.Length; i++) { q.SetParameter(i, values[i], types[i]); } results = q.List(); Assert.AreEqual(1, results.Count); hqlString = "from s in class Stuff where s.Foo.String is not null"; s.CreateQuery(hqlString).List(); hqlString = "from s in class Stuff where s.Foo > '0' order by s.Foo"; results = s.CreateQuery(hqlString).List(); Assert.AreEqual(1, results.Count); t.Commit(); } } FooProxy foo; using (ISession s = OpenSession()) { using (ITransaction t = s.BeginTransaction()) { foo = (FooProxy) s.Load(typeof(Foo), id); s.Load(more, more); t.Commit(); } } using (ISession s = OpenSession()) { using (ITransaction t = s.BeginTransaction()) { Stuff stuff = new Stuff(); stuff.Foo = foo; stuff.Id = 1234; stuff.MoreStuff = more; s.Load(stuff, stuff); Assert.AreEqual("More Stuff", stuff.MoreStuff.Name); s.Delete("from ms in class MoreStuff"); s.Delete("from foo in class Foo"); t.Commit(); } } }
//[Ignore("TimeZone Portions commented out - http://jira.nhibernate.org:8080/browse/NH-88")] public void AssociationId() { string id; Bar bar; MoreStuff more; using( ISession s = OpenSession() ) { using( ITransaction t = s.BeginTransaction() ) { bar = new Bar(); id = ( string ) s.Save( bar ); more = new MoreStuff(); more.Name = "More Stuff"; more.IntId = 12; more.StringId = "id"; Stuff stuf = new Stuff(); stuf.MoreStuff = more; more.Stuffs = new ArrayList(); more.Stuffs.Add( stuf ); stuf.Foo = bar; stuf.Id = 1234; //TODO: http://jira.nhibernate.org:8080/browse/NH-88 //stuf.setProperty(TimeZone.getDefault() ); s.Save( more ); t.Commit(); } } using( ISession s = OpenSession() ) { using( ITransaction t = s.BeginTransaction() ) { //The special property (lowercase) id may be used to reference the unique identifier of an object. (You may also use its property name.) string hqlString = "from s in class Stuff where s.Foo.id = ? and s.id.Id = ? and s.MoreStuff.id.IntId = ? and s.MoreStuff.id.StringId = ?"; object[ ] values = new object[ ] {bar, ( long ) 1234, 12, "id"}; IType[ ] types = new IType[ ] { NHibernateUtil.Entity( typeof( Foo ) ), NHibernateUtil.Int64, NHibernateUtil.Int32, NHibernateUtil.String }; IList results = s.Find( hqlString, values, types ); Assert.AreEqual( 1, results.Count ); hqlString = "from s in class Stuff where s.Foo.id = ? and s.id.Id = ? and s.MoreStuff.Name = ?"; values = new object[ ] {bar, ( long ) 1234, "More Stuff"}; types = new IType[ ] { NHibernateUtil.Entity( typeof( Foo ) ), NHibernateUtil.Int64, NHibernateUtil.String }; results = s.Find( hqlString, values, types ); Assert.AreEqual( 1, results.Count ); hqlString = "from s in class Stuff where s.Foo.String is not null"; s.Find( hqlString ); hqlString = "from s in class Stuff where s.Foo > '0' order by s.Foo"; results = s.Find( hqlString ); Assert.AreEqual( 1, results.Count ); t.Commit(); } } FooProxy foo; using( ISession s = OpenSession() ) { using( ITransaction t = s.BeginTransaction() ) { foo = ( FooProxy ) s.Load( typeof( Foo ), id ); s.Load( more, more ); t.Commit(); } } using( ISession s = OpenSession() ) { using( ITransaction t = s.BeginTransaction() ) { Stuff stuff = new Stuff(); stuff.Foo = foo; stuff.Id = 1234; stuff.MoreStuff = more; s.Load( stuff, stuff ); // TODO: figure out what to do with TimeZone // http://jira.nhibernate.org:8080/browse/NH-88 //Assert.IsTrue( stuff.getProperty().equals( TimeZone.getDefault() ) ); Assert.AreEqual( "More Stuff", stuff.MoreStuff.Name ); s.Delete( "from ms in class MoreStuff" ); s.Delete( "from foo in class Foo" ); t.Commit(); } } }