本文整理汇总了C#中NHibernate.DomainModel.Bar类的典型用法代码示例。如果您正苦于以下问题:C# Bar类的具体用法?C# Bar怎么用?C# Bar使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Bar类属于NHibernate.DomainModel命名空间,在下文中一共展示了Bar类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Query
public void Query()
{
ISession s = OpenSession();
ITransaction txn = s.BeginTransaction();
Foo foo = new Foo();
s.Save(foo);
Foo foo2 = new Foo();
s.Save(foo2);
foo.TheFoo = foo2;
IList list = s.CreateQuery("from Foo foo inner join fetch foo.TheFoo").List();
Foo foof = (Foo) list[0];
Assert.IsTrue(NHibernateUtil.IsInitialized(foof.TheFoo));
list = s.CreateQuery("from Baz baz left outer join fetch baz.FooToGlarch").List();
list = s.CreateQuery("select foo, bar from Foo foo left outer join foo.TheFoo bar where foo = ?")
.SetEntity(0, foo).List();
object[] row1 = (object[]) list[0];
Assert.IsTrue(row1[0] == foo && row1[1] == foo2);
s.CreateQuery("select foo.TheFoo.TheFoo.String from foo in class Foo where foo.TheFoo = 'bar'").List();
s.CreateQuery("select foo.TheFoo.TheFoo.TheFoo.String from foo in class Foo where foo.TheFoo.TheFoo = 'bar'").List();
s.CreateQuery("select foo.TheFoo.TheFoo.String from foo in class Foo where foo.TheFoo.TheFoo.TheFoo.String = 'bar'").
List();
// if( !( dialect is Dialect.HSQLDialect ) )
// {
s.CreateQuery("select foo.String from foo in class Foo where foo.TheFoo.TheFoo.TheFoo = foo.TheFoo.TheFoo").List();
// }
s.CreateQuery(
"select foo.String from foo in class Foo where foo.TheFoo.TheFoo = 'bar' and foo.TheFoo.TheFoo.TheFoo = 'baz'").List
();
s.CreateQuery(
"select foo.String from foo in class Foo where foo.TheFoo.TheFoo.TheFoo.String = 'a' and foo.TheFoo.String = 'b'").
List();
s.CreateQuery("from bar in class Bar, foo in elements(bar.Baz.FooArray)").List();
if (Dialect is DB2Dialect)
{
s.CreateQuery("from foo in class Foo where lower( foo.TheFoo.String ) = 'foo'").List();
s.CreateQuery("from foo in class Foo where lower( (foo.TheFoo.String || 'foo') || 'bar' ) = 'foo'").List();
s.CreateQuery("from foo in class Foo where repeat( (foo.TheFoo.STring || 'foo') || 'bar', 2 ) = 'foo'").List();
s.CreateQuery(
"From foo in class Bar where foo.TheFoo.Integer is not null and repeat( (foo.TheFoo.String || 'foo') || 'bar', (5+5)/2 ) = 'foo'")
.List();
s.CreateQuery(
"From foo in class Bar where foo.TheFoo.Integer is not null or repeat( (foo.TheFoo.String || 'foo') || 'bar', (5+5)/2 ) = 'foo'")
.List();
}
if ((Dialect is SybaseDialect) || (Dialect is MsSql2000Dialect))
{
s.CreateQuery("select baz from Baz as baz join baz.FooArray foo group by baz order by sum(foo.Float)").Enumerable();
}
s.CreateQuery("from Foo as foo where foo.Component.Glarch.Name is not null").List();
s.CreateQuery("from Foo as foo left outer join foo.Component.Glarch as glarch where glarch.Name = 'foo'").List();
list = s.CreateQuery("from Foo").List();
Assert.AreEqual(2, list.Count);
Assert.IsTrue(list[0] is FooProxy);
list = s.CreateQuery("from Foo foo left outer join foo.TheFoo").List();
Assert.AreEqual(2, list.Count);
Assert.IsTrue(((object[]) list[0])[0] is FooProxy);
s.CreateQuery("From Foo, Bar").List();
s.CreateQuery("from Baz baz left join baz.FooToGlarch, Bar bar join bar.TheFoo").List();
s.CreateQuery("from Baz baz left join baz.FooToGlarch join baz.FooSet").List();
s.CreateQuery("from Baz baz left join baz.FooToGlarch join fetch baz.FooSet foo left join fetch foo.TheFoo").List();
list =
s.CreateQuery(
"from foo in class NHibernate.DomainModel.Foo where foo.String='osama bin laden' and foo.Boolean = true order by foo.String asc, foo.Component.Count desc")
.List();
Assert.AreEqual(0, list.Count, "empty query");
IEnumerable enumerable =
s.CreateQuery(
"from foo in class NHibernate.DomainModel.Foo where foo.String='osama bin laden' order by foo.String asc, foo.Component.Count desc")
.Enumerable();
Assert.IsTrue(IsEmpty(enumerable), "empty enumerator");
list = s.CreateQuery("select foo.TheFoo from foo in class NHibernate.DomainModel.Foo").List();
Assert.AreEqual(1, list.Count, "query");
Assert.AreEqual(foo.TheFoo, list[0], "returned object");
foo.TheFoo.TheFoo = foo;
foo.String = "fizard";
if (Dialect.SupportsSubSelects)
{
if (!(Dialect is FirebirdDialect))
{
if (IsClassicParser)
{
list =
s.CreateQuery("from foo in class NHibernate.DomainModel.Foo where ? = some foo.Component.ImportantDates.elements")
.SetDateTime(0, DateTime.Today).List();
//.........这里部分代码省略.........
开发者ID:remcoros,项目名称:nhibernate,代码行数:101,代码来源:FooBarTest.cs
示例2: Find
public void Find()
{
ISession s = OpenSession();
ITransaction txn = s.BeginTransaction();
// some code commented out in h2.0.3
Bar bar = new Bar();
s.Save(bar);
bar.BarString = "bar bar";
bar.String = "xxx";
Foo foo = new Foo();
s.Save(foo);
foo.String = "foo bar";
s.Save(new Foo());
s.Save(new Bar());
IList list1 =
s.CreateQuery("select foo from foo in class NHibernate.DomainModel.Foo where foo.String='foo bar'").List();
Assert.AreEqual(1, list1.Count, "find size");
Assert.AreSame(foo, list1[0], "find ==");
IList list2 = s.CreateQuery("from foo in class NHibernate.DomainModel.Foo order by foo.String, foo.Date").List();
Assert.AreEqual(4, list2.Count, "find size");
list1 = s.CreateQuery("from foo in class NHibernate.DomainModel.Foo where foo.class='B'").List();
Assert.AreEqual(2, list1.Count, "class special property");
list1 =
s.CreateQuery("from foo in class NHibernate.DomainModel.Foo where foo.class=NHibernate.DomainModel.Bar").List();
Assert.AreEqual(2, list1.Count, "class special property");
list1 = s.CreateQuery("from foo in class NHibernate.DomainModel.Foo where foo.class=Bar").List();
list2 =
s.CreateQuery(
"select bar from bar in class NHibernate.DomainModel.Bar, foo in class NHibernate.DomainModel.Foo where bar.String = foo.String and not bar=foo")
.List();
Assert.AreEqual(2, list1.Count, "class special property");
Assert.AreEqual(1, list2.Count, "select from a subclass");
Trivial t = new Trivial();
s.Save(t);
txn.Commit();
s.Close();
s = OpenSession();
txn = s.BeginTransaction();
list1 = s.CreateQuery("from foo in class NHibernate.DomainModel.Foo where foo.String='foo bar'").List();
Assert.AreEqual(1, list1.Count, "find count");
// There is an interbase bug that causes null integers to return as 0, also numeric precision is <=15 -h2.0.3 comment
Assert.IsTrue(((Foo) list1[0]).EqualsFoo(foo), "find equals");
list2 = s.CreateQuery("select foo from foo in class NHibernate.DomainModel.Foo").List();
Assert.AreEqual(5, list2.Count, "find count");
IList list3 = s.CreateQuery("from bar in class NHibernate.DomainModel.Bar where bar.BarString='bar bar'").List();
Assert.AreEqual(1, list3.Count, "find count");
Assert.IsTrue(list2.Contains(list1[0]) && list2.Contains(list2[0]), "find same instance");
Assert.AreEqual(1, s.CreateQuery("from t in class NHibernate.DomainModel.Trivial").List().Count);
s.Delete("from t in class NHibernate.DomainModel.Trivial");
list2 =
s.CreateQuery("from foo in class NHibernate.DomainModel.Foo where foo.Date = ?").SetDateTime(0,
new DateTime(1970, 01,
01)).List();
Assert.AreEqual(4, list2.Count, "find by date");
IEnumerator enumer = list2.GetEnumerator();
while (enumer.MoveNext())
{
s.Delete(enumer.Current);
}
list2 = s.CreateQuery("from foo in class NHibernate.DomainModel.Foo").List();
Assert.AreEqual(0, list2.Count, "find deleted");
txn.Commit();
s.Close();
}
开发者ID:remcoros,项目名称:nhibernate,代码行数:73,代码来源:FooBarTest.cs
示例3: RecursiveLoad
public void RecursiveLoad()
{
// Non polymorphisc class (there is an implementation optimization
// being tested here) - from h2.0.3 - what does that mean?
ISession s = OpenSession();
ITransaction txn = s.BeginTransaction();
GlarchProxy last = new Glarch();
s.Save(last);
last.Order = 0;
for (int i = 0; i < 5; i++)
{
GlarchProxy next = new Glarch();
s.Save(next);
last.Next = next;
last = next;
last.Order = (short) (i + 1);
}
IEnumerator enumer = s.CreateQuery("from g in class NHibernate.DomainModel.Glarch").Enumerable().GetEnumerator();
while (enumer.MoveNext())
{
object objTemp = enumer.Current;
}
IList list = s.CreateQuery("from g in class NHibernate.DomainModel.Glarch").List();
Assert.AreEqual(6, list.Count, "recursive find");
txn.Commit();
s.Close();
s = OpenSession();
txn = s.BeginTransaction();
list = s.CreateQuery("from g in class NHibernate.DomainModel.Glarch").List();
Assert.AreEqual(6, list.Count, "recursive iter");
list = s.CreateQuery("from g in class NHibernate.DomainModel.Glarch where g.Next is not null").List();
Assert.AreEqual(5, list.Count, "exclude the null next");
txn.Commit();
s.Close();
s = OpenSession();
txn = s.BeginTransaction();
enumer =
s.CreateQuery("from g in class NHibernate.DomainModel.Glarch order by g.Order asc").Enumerable().GetEnumerator();
while (enumer.MoveNext())
{
GlarchProxy g = (GlarchProxy) enumer.Current;
Assert.IsNotNull(g, "not null");
// no equiv in .net - so ran a delete query
// iter.remove();
}
s.Delete("from NHibernate.DomainModel.Glarch as g");
txn.Commit();
s.Close();
// same thing bug using polymorphic class (no optimization possible)
s = OpenSession();
txn = s.BeginTransaction();
FooProxy flast = new Bar();
s.Save(flast);
for (int i = 0; i < 5; i++)
{
FooProxy foo = new Bar();
s.Save(foo);
flast.TheFoo = foo;
flast = flast.TheFoo;
flast.String = "foo" + (i + 1);
}
enumer = s.CreateQuery("from foo in class NHibernate.DomainModel.Foo").Enumerable().GetEnumerator();
while (enumer.MoveNext())
{
object objTemp = enumer.Current;
}
list = s.CreateQuery("from foo in class NHibernate.DomainModel.Foo").List();
Assert.AreEqual(6, list.Count, "recursive find");
txn.Commit();
s.Close();
s = OpenSession();
txn = s.BeginTransaction();
list = s.CreateQuery("from foo in class NHibernate.DomainModel.Foo").List();
Assert.AreEqual(6, list.Count, "recursive iter");
enumer = list.GetEnumerator();
while (enumer.MoveNext())
{
Assert.IsTrue(enumer.Current is BarProxy, "polymorphic recursive load");
}
txn.Commit();
s.Close();
s = OpenSession();
txn = s.BeginTransaction();
enumer =
s.CreateQuery("from foo in class NHibernate.DomainModel.Foo order by foo.String asc").Enumerable().GetEnumerator();
string currentString = String.Empty;
while (enumer.MoveNext())
{
BarProxy bar = (BarProxy) enumer.Current;
//.........这里部分代码省略.........
开发者ID:remcoros,项目名称:nhibernate,代码行数:101,代码来源:FooBarTest.cs
示例4: Polymorphism
public void Polymorphism()
{
ISession s = OpenSession();
Bar bar = new Bar();
s.Save(bar);
bar.BarString = "bar bar";
s.Flush();
s.Close();
s = OpenSession();
FooProxy foo = (FooProxy) s.Load(typeof(Foo), bar.Key);
Assert.IsTrue(foo is BarProxy, "polymorphic");
Assert.IsTrue(((BarProxy) foo).BarString.Equals(bar.BarString), "subclass property");
s.Delete(foo);
s.Flush();
s.Close();
}
开发者ID:remcoros,项目名称:nhibernate,代码行数:17,代码来源:FooBarTest.cs
示例5: CollectionOfSelf
public void CollectionOfSelf()
{
ISession s = OpenSession();
Bar bar = new Bar();
s.Save(bar);
// h2.0.3 was a set
bar.Abstracts = new HashedSet();
bar.Abstracts.Add(bar);
Bar bar2 = new Bar();
bar.Abstracts.Add(bar2);
bar.TheFoo = bar;
s.Save(bar2);
s.Flush();
s.Close();
bar.Abstracts = null;
s = OpenSession();
s.Load(bar, bar.Key);
Assert.AreEqual(2, bar.Abstracts.Count);
Assert.IsTrue(bar.Abstracts.Contains(bar), "collection contains self");
Assert.AreSame(bar, bar.TheFoo, "association to self");
if (Dialect is MySQLDialect)
{
// Break the self-reference cycle to avoid error when deleting the row
bar.TheFoo = null;
s.Flush();
}
foreach (object obj in bar.Abstracts)
{
s.Delete(obj);
}
s.Flush();
s.Close();
}
开发者ID:remcoros,项目名称:nhibernate,代码行数:38,代码来源:FooBarTest.cs
示例6: CollectionsInSelect
public void CollectionsInSelect()
{
ISession s = OpenSession();
// ITransaction t = s.BeginTransaction();
Foo[ ] foos = new Foo[ ] {null, new Foo()};
s.Save( foos[ 1 ] );
Baz baz = new Baz();
baz.SetDefaults();
baz.FooArray = foos;
s.Save( baz );
Baz baz2 = new Baz();
baz2.SetDefaults();
s.Save( baz2 );
Bar bar = new Bar();
bar.Baz = baz;
s.Save( bar );
IList list = s.Find( "select new Result(foo.String, foo.Long, foo.Integer) from foo in class Foo" );
Assert.AreEqual( 2, list.Count );
Assert.IsTrue( list[ 0 ] is Result );
Assert.IsTrue( list[ 1 ] is Result );
list = s.Find( "select new Result( baz.Name, foo.Long, count(elements(baz.FooArray)) ) from Baz baz join baz.FooArray foo group by baz.Name, foo.Long" );
Assert.AreEqual( 1, list.Count );
Assert.IsTrue( list[ 0 ] is Result );
Result r = ( Result ) list[ 0 ];
Assert.AreEqual( baz.Name, r.Name );
Assert.AreEqual( 1, r.Count );
Assert.AreEqual( foos[ 1 ].Long, r.Amount );
list = s.Find( "select new Result( baz.Name, max(foo.Long), count(foo) ) from Baz baz join baz.FooArray foo group by baz.Name" );
Assert.AreEqual( 1, list.Count );
Assert.IsTrue( list[ 0 ] is Result );
r = ( Result ) list[ 0 ];
Assert.AreEqual( baz.Name, r.Name );
Assert.AreEqual( 1, r.Count );
// TODO: figure out a better way
// in hibernate this is hard coded as 696969696969696938l which is very dependant upon
// how the test are run because it is calculated on a global static variable...
// maybe a better way to test this would be to assume that the first
//Assert.AreEqual( 696969696969696969L, r.Amount );
s.Find( "select max( elements(bar.Baz.FooArray) ) from Bar as bar" );
// the following test is disable for databases with no subselects... also for Interbase (not sure why) - comment from h2.0.3
if( dialect.SupportsSubSelects )
{
s.Find( "select count(*) from Baz as baz where 1 in indices(baz.FooArray)" );
s.Find( "select count(*) from Bar as bar where 'abc' in elements(bar.Baz.FooArray)" );
s.Find( "select count(*) from Bar as bar where 1 in indices(bar.Baz.FooArray)" );
if( !( dialect is Dialect.OracleDialect ) )
{
// These fail on Oracle 10 XE - g.id is a string (guid), indices are integer
s.Find( "select count(*) from Bar as bar, bar.Component.Glarch.ProxyArray as g where g.id in indices(bar.Baz.FooArray)" );
s.Find( "select max( elements(bar.Baz.FooArray) ) from Bar as bar, bar.Component.Glarch.ProxyArray as g where g.id in indices(bar.Baz.FooArray)" );
}
s.Find( "select count(*) from Bar as bar where 1 in (from bar.Component.Glarch.ProxyArray g where g.Name='foo')" );
s.Find( "select count(*) from Bar as bar where 1 in (from g in bar.Component.Glarch.ProxyArray.elements where g.Name='foo')" );
// TODO: figure out why this is throwing an ORA-1722 error
if( !( dialect is Oracle9Dialect ) )
{
s.Find( "select count(*) from Bar as bar left outer join bar.Component.Glarch.ProxyArray as pg where 1 in (from g in bar.Component.Glarch.ProxyArray)" );
}
}
list = s.Find( "from Baz baz left join baz.FooToGlarch join fetch baz.FooArray foo left join fetch foo.TheFoo" );
Assert.AreEqual( 1, list.Count );
Assert.AreEqual( 2, ( ( object[ ] ) list[ 0 ] ).Length );
list = s.Find( "select baz.Name from Bar bar inner join bar.Baz baz inner join baz.FooSet foo where baz.Name = bar.String" );
s.Find( "SELECT baz.Name FROM Bar AS bar INNER JOIN bar.Baz AS baz INNER JOIN baz.FooSet AS foo WHERE baz.Name = bar.String" );
s.Find( "select baz.Name from Bar bar join bar.Baz baz left outer join baz.FooSet foo where baz.Name = bar.String" );
s.Find( "select baz.Name from Bar bar, bar.Baz baz, baz.FooSet foo where baz.Name = bar.String" );
s.Find( "SELECT baz.Name FROM Bar AS bar, bar.Baz AS baz, baz.FooSet AS foo WHERE baz.Name = bar.String" );
s.Find( "select baz.Name from Bar bar left join bar.Baz baz left join baz.FooSet foo where baz.Name = bar.String" );
s.Find( "select foo.String from Bar bar left join bar.Baz.FooSet foo where bar.String = foo.String" );
s.Find( "select baz.Name from Bar bar left join bar.Baz baz left join baz.FooArray foo where baz.Name = bar.String" );
s.Find( "select foo.String from Bar bar left join bar.Baz.FooArray foo where bar.String = foo.String" );
s.Find( "select bar.String, foo.String from bar in class Bar inner join bar.Baz as baz inner join elements(baz.FooSet) as foo where baz.Name = 'name'" );
s.Find( "select foo from bar in class Bar inner join bar.Baz as baz inner join baz.FooSet as foo" );
s.Find( "select foo from bar in class Bar inner join bar.Baz.FooSet as foo" );
s.Find( "select bar.String, foo.String from bar in class Bar, bar.Baz as baz, elements(baz.FooSet) as foo where baz.Name = 'name'" );
s.Find( "select foo from bar in class Bar, bar.Baz as baz, baz.FooSet as foo" );
s.Find( "select foo from bar in class Bar, bar.Baz.FooSet as foo" );
Assert.AreEqual( 1, s.Find( "from Bar bar join bar.Baz.FooArray foo" ).Count );
Assert.AreEqual( 0, s.Find( "from bar in class Bar, foo in bar.Baz.FooSet.elements" ).Count );
Assert.AreEqual( 1, s.Find( "from bar in class Bar, foo in elements( bar.Baz.FooArray )" ).Count );
//.........这里部分代码省略.........
开发者ID:rcarrillopadron,项目名称:nhibernate-1.0.2.0,代码行数:101,代码来源:FooBarTest.cs
示例7: Load
public void Load()
{
ISession s = OpenSession();
Qux q = new Qux();
s.Save(q);
BarProxy b = new Bar();
s.Save(b);
s.Flush();
s.Close();
s = OpenSession();
q = (Qux) s.Load(typeof(Qux), q.Key);
b = (BarProxy) s.Load(typeof(Foo), b.Key);
string tempKey = b.Key;
Assert.IsFalse(NHibernateUtil.IsInitialized(b), "b should have been an unitialized Proxy");
string tempString = b.BarString;
Assert.IsTrue(NHibernateUtil.IsInitialized(b), "b should have been an initialized Proxy");
BarProxy b2 = (BarProxy) s.Load(typeof(Bar), tempKey);
Qux q2 = (Qux) s.Load(typeof(Qux), q.Key);
Assert.AreSame(q, q2, "loaded same Qux");
Assert.AreSame(b, b2, "loaded same BarProxy");
s.Delete(q2);
s.Delete(b2);
s.Flush();
s.Close();
}
开发者ID:remcoros,项目名称:nhibernate,代码行数:26,代码来源:FooBarTest.cs
示例8: AssociationId
//[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())
{
//.........这里部分代码省略.........
开发者ID:remcoros,项目名称:nhibernate,代码行数:101,代码来源:FooBarTest.cs
示例9: CollectionsInSelect
public void CollectionsInSelect()
{
ISession s = OpenSession();
ITransaction t = s.BeginTransaction();
Foo[] foos = new Foo[] {null, new Foo()};
s.Save(foos[1]);
Baz baz = new Baz();
baz.SetDefaults();
baz.FooArray = foos;
s.Save(baz);
Baz baz2 = new Baz();
baz2.SetDefaults();
s.Save(baz2);
Bar bar = new Bar();
bar.Baz = baz;
s.Save(bar);
IList list = s.CreateQuery("select new Result(foo.String, foo.Long, foo.Integer) from foo in class Foo").List();
Assert.AreEqual(2, list.Count);
Assert.IsTrue(list[0] is Result);
Assert.IsTrue(list[1] is Result);
list =
s.CreateQuery(
"select new Result( baz.Name, foo.Long, count(elements(baz.FooArray)) ) from Baz baz join baz.FooArray foo group by baz.Name, foo.Long")
.List();
Assert.AreEqual(1, list.Count);
Assert.IsTrue(list[0] is Result);
Result r = (Result) list[0];
Assert.AreEqual(baz.Name, r.Name);
Assert.AreEqual(1, r.Count);
Assert.AreEqual(foos[1].Long, r.Amount);
list =
s.CreateQuery(
"select new Result( baz.Name, max(foo.Long), count(foo) ) from Baz baz join baz.FooArray foo group by baz.Name").
List();
Assert.AreEqual(1, list.Count);
Assert.IsTrue(list[0] is Result);
r = (Result) list[0];
Assert.AreEqual(baz.Name, r.Name);
Assert.AreEqual(1, r.Count);
s.CreateQuery("select max( elements(bar.Baz.FooArray) ) from Bar as bar").List();
// the following test is disable for databases with no subselects... also for Interbase (not sure why) - comment from h2.0.3
if (Dialect.SupportsSubSelects)
{
s.CreateQuery("select count(*) from Baz as baz where 1 in indices(baz.FooArray)").List();
s.CreateQuery("select count(*) from Bar as bar where 'abc' in elements(bar.Baz.FooArray)").List();
s.CreateQuery("select count(*) from Bar as bar where 1 in indices(bar.Baz.FooArray)").List();
s.CreateQuery(
"select count(*) from Bar as bar where '1' in (from bar.Component.Glarch.ProxyArray g where g.Name='foo')").List();
// The nex query is wrong and is not present in H3.2:
// The SQL result, from Classic parser, is the same of the previous query.
// The AST parser has some problem to parse 'from g in bar.Component.Glarch.ProxyArray'
// which should be parsed as 'from bar.Component.Glarch.ProxyArray g'
//s.CreateQuery(
// "select count(*) from Bar as bar where '1' in (from g in bar.Component.Glarch.ProxyArray.elements where g.Name='foo')")
// .List();
// TODO: figure out why this is throwing an ORA-1722 error
// probably the conversion ProxyArray.id (to_number ensuring a not null value)
if (!(Dialect is Oracle8iDialect))
{
s.CreateQuery(
"select count(*) from Bar as bar join bar.Component.Glarch.ProxyArray as g where cast(g.id as Int32) in indices(bar.Baz.FooArray)").
List();
s.CreateQuery(
"select max( elements(bar.Baz.FooArray) ) from Bar as bar join bar.Component.Glarch.ProxyArray as g where cast(g.id as Int32) in indices(bar.Baz.FooArray)")
.List();
s.CreateQuery(
"select count(*) from Bar as bar left outer join bar.Component.Glarch.ProxyArray as pg where '1' in (from g in bar.Component.Glarch.ProxyArray)")
.List();
}
}
list =
s.CreateQuery("from Baz baz left join baz.FooToGlarch join fetch baz.FooArray foo left join fetch foo.TheFoo").List();
Assert.AreEqual(1, list.Count);
Assert.AreEqual(2, ((object[]) list[0]).Length);
list =
s.CreateQuery(
"select baz.Name from Bar bar inner join bar.Baz baz inner join baz.FooSet foo where baz.Name = bar.String").List();
s.CreateQuery(
"SELECT baz.Name FROM Bar AS bar INNER JOIN bar.Baz AS baz INNER JOIN baz.FooSet AS foo WHERE baz.Name = bar.String")
.List();
s.CreateQuery(
"select baz.Name from Bar bar join bar.Baz baz left outer join baz.FooSet foo where baz.Name = bar.String").List();
s.CreateQuery("select baz.Name from Bar bar join bar.Baz baz join baz.FooSet foo where baz.Name = bar.String").List();
s.CreateQuery("SELECT baz.Name FROM Bar AS bar join bar.Baz AS baz join baz.FooSet AS foo WHERE baz.Name = bar.String").List();
s.CreateQuery(
"select baz.Name from Bar bar left join bar.Baz baz left join baz.FooSet foo where baz.Name = bar.String").List();
//.........这里部分代码省略.........
开发者ID:remcoros,项目名称:nhibernate,代码行数:101,代码来源:FooBarTest.cs
示例10: NamedParams
public void NamedParams()
{
Bar bar = new Bar();
Bar bar2 = new Bar();
bar.Name = "Bar";
bar2.Name = "Bar Two";
Baz baz = new Baz();
baz.CascadingBars = new HashedSet();
baz.CascadingBars.Add(bar);
bar.Baz = baz;
ISession s = OpenSession();
ITransaction txn = s.BeginTransaction();
s.Save(baz);
s.Save(bar2);
IList list =
s.CreateQuery("from Bar bar left join bar.Baz baz left join baz.CascadingBars b where bar.Name like 'Bar %'").List();
object row = list[0];
Assert.IsTrue(row is object[] && ((object[]) row).Length == 3);
IQuery q = s.CreateQuery(
"select bar, b " +
"from Bar bar " +
"left join bar.Baz baz left join baz.CascadingBars b " +
"where (bar.Name in (:nameList) or bar.Name in (:nameList)) and bar.String = :stringVal");
IList nameList = new ArrayList();
nameList.Add("bar");
nameList.Add("Bar");
nameList.Add("Bar Two");
q.SetParameterList("nameList", nameList);
q.SetParameter("stringVal", "a string");
list = q.List();
// a check for SAPDialect here
Assert.AreEqual(2, list.Count);
q = s.CreateQuery(
"select bar, b " +
"from Bar bar " +
"inner join bar.Baz baz inner join baz.CascadingBars b " +
"where bar.Name like 'Bar%'");
list = q.List();
Assert.AreEqual(1, list.Count);
q = s.CreateQuery(
"select bar, b " +
"from Bar bar " +
"left join bar.Baz baz left join baz.CascadingBars b " +
"where bar.Name like :name and b.Name like :name");
// add a check for HSQLDialect
q.SetString("name", "Bar%");
list = q.List();
Assert.AreEqual(1, list.Count);
s.Delete(baz);
s.Delete(bar2);
txn.Commit();
s.Close();
}
开发者ID:remcoros,项目名称:nhibernate,代码行数:61,代码来源:FooBarTest.cs
示例11: ComponentParent
public void ComponentParent()
{
ISession s = OpenSession();
ITransaction t = s.BeginTransaction();
BarProxy bar = new Bar();
bar.Component = new FooComponent();
Baz baz = new Baz();
baz.Components = new FooComponent[] {new FooComponent(), new FooComponent()};
s.Save(bar);
s.Save(baz);
t.Commit();
s.Close();
s = OpenSession();
t = s.BeginTransaction();
bar = (BarProxy) s.Load(typeof(Bar), bar.Key);
s.Load(baz, baz.Code);
Assert.AreEqual(bar, bar.BarComponent.Parent);
Assert.IsTrue(baz.Components[0].Baz == baz && baz.Components[1].Baz == baz);
s.Delete(baz);
s.Delete(bar);
t.Commit();
s.Close();
}
开发者ID:remcoros,项目名称:nhibernate,代码行数:29,代码来源:FooBarTest.cs
示例12: QueryLockMode
public void QueryLockMode()
{
ISession s = OpenSession();
ITransaction tx = s.BeginTransaction();
Bar bar = new Bar();
Assert.IsNull(bar.Bytes);
s.Save(bar);
Assert.IsNotNull(bar.Bytes);
s.Flush();
Assert.IsNotNull(bar.Bytes);
bar.String = "changed";
Baz baz = new Baz();
baz.Foo = bar;
s.Save(baz);
Assert.IsNotNull(bar.Bytes);
IQuery q = s.CreateQuery("from Foo foo, Bar bar");
q.SetLockMode("bar", LockMode.Upgrade);
object[] result = (object[]) q.List()[0];
Assert.IsNotNull(bar.Bytes);
object b = result[0];
Assert.IsTrue(s.GetCurrentLockMode(b) == LockMode.Write && s.GetCurrentLockMode(result[1]) == LockMode.Write);
tx.Commit();
Assert.IsNotNull(bar.Bytes);
s.Disconnect();
s.Reconnect();
tx = s.BeginTransaction();
Assert.IsNotNull(bar.Bytes);
Assert.AreEqual(LockMode.None, s.GetCurrentLockMode(b));
Assert.IsNotNull(bar.Bytes);
s.CreateQuery("from Foo foo").List();
Assert.IsNotNull(bar.Bytes);
Assert.AreEqual(LockMode.None, s.GetCurrentLockMode(b));
q = s.CreateQuery("from Foo foo");
q.SetLockMode("foo", LockMode.Read);
q.List();
Assert.AreEqual(LockMode.Read, s.GetCurrentLockMode(b));
s.Evict(baz);
tx.Commit();
s.Disconnect();
s.Reconnect();
tx = s.BeginTransaction();
Assert.AreEqual(LockMode.None, s.GetCurrentLockMode(b));
s.Delete(s.Load(typeof(Baz), baz.Code));
Assert.AreEqual(LockMode.None, s.GetCurrentLockMode(b));
tx.Commit();
s.Close();
s = OpenSession();
tx = s.BeginTransaction();
q = s.CreateQuery("from Foo foo, Bar bar, Bar bar2");
q.SetLockMode("bar", LockMode.Upgrade);
q.SetLockMode("bar2", LockMode.Read);
result = (object[]) q.List()[0];
Assert.IsTrue(s.GetCurrentLockMode(result[0]) == LockMode.Upgrade &&
s.GetCurrentLockMode(result[1]) == LockMode.Upgrade);
s.Delete(result[0]);
tx.Commit();
s.Close();
}
开发者ID:remcoros,项目名称:nhibernate,代码行数:72,代码来源:FooBarTest.cs
示例13: CollectionsInSelect
public void CollectionsInSelect()
{
ISession s = OpenSession();
ITransaction t = s.BeginTransaction();
Foo[] foos = new Foo[] {null, new Foo()};
s.Save(foos[1]);
Baz baz = new Baz();
baz.SetDefaults();
baz.FooArray = foos;
s.Save(baz);
Baz baz2 = new Baz();
baz2.SetDefaults();
s.Save(baz2);
Bar bar = new Bar();
bar.Baz = baz;
s.Save(bar);
IList list = s.CreateQuery("select new Result(foo.String, foo.Long, foo.Integer) from foo in class Foo").List();
Assert.AreEqual(2, list.Count);
Assert.IsTrue(list[0] is Result);
Assert.IsTrue(list[1] is Result);
list =
s.CreateQuery(
"select new Result( baz.Name, foo.Long, count(elements(baz.FooArray)) ) from Baz baz join baz.FooArray foo group by baz.Name, foo.Long")
.List();
Assert.AreEqual(1, list.Count);
Assert.IsTrue(list[0] is Result);
Result r = (Result) list[0];
Assert.AreEqual(baz.Name, r.Name);
Assert.AreEqual(1, r.Count);
Assert.AreEqual(foos[1].Long, r.Amount);
list =
s.CreateQuery(
"select new Result( baz.Name, max(foo.Long), count(foo) ) from Baz baz join baz.FooArray foo group by baz.Name").
List();
Assert.AreEqual(1, list.Count);
Assert.IsTrue(list[0] is Result);
r = (Result) list[0];
Assert.AreEqual(baz.Name, r.Name);
Assert.AreEqual(1, r.Count);
s.CreateQuery("select max( elements(bar.Baz.FooArray) ) from Bar as bar").List();
// the following test is disable for databases with no subselects... also for Interbase (not sure why) - comment from h2.0.3
if (Dialect.SupportsSubSelects)
{
s.CreateQuery("select count(*) from Baz as baz where 1 in indices(baz.FooArray)").List();
s.CreateQuery("select count(*) from Bar as bar where 'abc' in elements(bar.Baz.FooArray)").List();
s.CreateQuery("select count(*) from Bar as bar where 1 in indices(bar.Baz.FooArray)").List();
s.CreateQuery(
"select count(*) from Bar as bar, bar.Component.Glarch.ProxyArray as g where g.id in indices(bar.Baz.FooArray)").
List();
s.CreateQuery(
"select max( elements(bar.Baz.FooArray) ) from Bar as bar, bar.Component.Glarch.ProxyArray as g where g.id in indices(bar.Baz.FooArray)")
.List();
s.CreateQuery(
"select count(*) from Bar as bar where 1 in (from bar.Component.Glarch.ProxyArray g where g.Name='foo')").List();
s.CreateQuery(
"select count(*) from Bar as bar where 1 in (from g in bar.Component.Glarch.ProxyArray.elements where g.Name='foo')")
.List();
// TODO: figure out why this is throwing an ORA-1722 error
if (!(Dialect is Oracle9Dialect))
{
s.CreateQuery(
"select count(*) from Bar as bar left outer join bar.Component.Glarch.ProxyArray as pg where 1 in (from g in bar.Component.Glarch.ProxyArray)")
.List();
}
}
list =
s.CreateQuery("from Baz baz left join baz.FooToGlarch join fetch baz.FooArray foo left join fetch foo.TheFoo").List();
Assert.AreEqual(1, list.Count);
Assert.AreEqual(2, ((object[]) list[0]).Length);
list =
s.CreateQuery(
"select baz.Name from Bar bar inner join bar.Baz baz inner join baz.FooSet foo where baz.Name = bar.String").List();
s.CreateQuery(
"SELECT baz.Name FROM Bar AS bar INNER JOIN bar.Baz AS baz INNER JOIN baz.FooSet AS foo WHERE baz.Name = bar.String")
.List();
s.CreateQuery(
"select baz.Name from Bar bar join bar.Baz baz left outer join baz.FooSet foo where baz.Name = bar.String").List();
s.CreateQuery("select baz.Name from Bar bar, bar.Baz baz, baz.FooSet foo where baz.Name = bar.String").List();
s.CreateQuery("SELECT baz.Name FROM Bar AS bar, bar.Baz AS baz, baz.FooSet AS foo WHERE baz.Name = bar.String").List();
s.CreateQuery(
"select baz.Name from Bar bar left join bar.Baz baz left join baz.FooSet foo where baz.Name = bar.String").List();
s.CreateQuery("select foo.String from Bar bar left join bar.Baz.FooSet foo where bar.String = foo.String").List();
s.CreateQuery(
"select baz.Name from Bar bar left join bar.Baz baz left join baz.FooArray foo where baz.Name = bar.String").List();
s.CreateQuery("select foo.String from Bar bar left join bar.Baz.FooArray foo where bar.String = foo.String").List();
s.CreateQuery(
//.........这里部分代码省略.........
开发者ID:aistrate,项目名称:TypingPracticeTexts,代码行数:101,代码来源:FooBarTest.cs
示例14: Databinder
public void Databinder()
{
BarProxy bar;
FooProxy foo, foo2;
Baz baz;
using( ISession s = OpenSession() )
{
bar = new Bar();
s.Save( bar );
foo = new Foo();
s.Save( foo );
foo2 = new Foo();
s.Save( foo2 );
foo2.TheFoo = foo;
baz = new Baz();
s.Save( baz );
baz.SetDefaults();
baz.FooArray = new FooProxy[ ] {foo, foo2, bar, null};
bar.TheFoo = foo;
s.Flush();
}
using( ISession s = OpenSession() )
{
bar = ( BarProxy ) s.Load( typeof( Foo ), bar.Key );
foo = ( FooProxy ) s.Load( typeof( Foo ), foo.Key );
foo2 = ( FooProxy ) s.Load( typeof( Foo ), foo2.Key );
baz = ( Baz ) s.Load( typeof( Baz ), baz.Code );
IDatabinder binder = sessions.OpenDatabinder();
binder.InitializeLazy = true;
binder
.Bind( foo2 )
.Bind( baz )
.Bind( foo )
.Bind( bar );
Console.WriteLine( binder.ToGenericXml() );
binder
.Bind( foo2 )
.Bind( baz );
Console.WriteLine( binder.ToXML() );
//assertTrue( "dom", binder.toDOM()!=null );
//assertTrue( "generic dom", binder.toGenericDOM()!=null );
s.Delete( foo );
s.Delete( baz );
s.Delete( bar );
s.Delete( foo2 );
s.Flush();
}
}
开发者ID:rcarrillopadron,项目名称:nhibernate-1.0.2.0,代码行数:60,代码来源:FooBarTest.cs
示例15: Any
public void Any()
{
ISession s = OpenSession();
One one = new One();
BarProxy foo = new Bar();
foo.Object = one;
object fid = s.Save(foo);
object oid = one.Key;
s.Flush();
s.Close();
s = OpenSession();
IList list = s.CreateQuery("from Bar bar where bar.Object.id = ? and bar.Object.class = ?")
.SetParameter(0, oid, NHibernateUtil.Int64).SetParameter(1, typeof(One).FullName, NHibernateUtil.ClassMetaType).List();
Assert.AreEqual(1, list.Count);
// this is a little different from h2.0.3 because the full type is stored, not
// just the class name.
list =
s.CreateQuery(
"select one from One one, Bar bar where bar.Object.id = one.id and bar.Object.class LIKE 'NHibernate.DomainModel.One%'")
.List();
Assert.AreEqual(1, list.Count);
s.Flush();
s.Close();
s = OpenSession();
foo = (BarProxy) s.Load(typeof(Foo), fid);
Assert.IsNotNull(foo);
Assert.IsTrue(foo.Object is One);
Assert.AreEqual(oid, s.GetIdentifier(foo.Object));
s.Delete(foo);
s.Delete(foo.Object);
s.Flush();
s.Close();
}
开发者ID:remcoros,项目名称:nhibernate,代码行数:36,代码来源:FooBarTest.cs
示例16: PersistCollections
public void PersistCollections()
{
ISession s = OpenSession();
ITransaction txn = s.BeginTransaction();
IEnumerator enumer = s.CreateQuery("select count(*) from b in class Bar").Enumerable().GetEnumerator();
enumer.MoveNext();
Assert.AreEqual(0L, enumer.Current);
Baz baz = new Baz();
s.Save(baz);
baz.SetDefaults();
baz.StringArray = new string[] {"stuff"};
ISet bars = new HashedSet();
bars.Add(new Bar());
baz.CascadingBars = bars;
IDictionary sgm = new Hashtable();
sgm["a"] = new Glarch();
sgm["b"] = new Glarch();
baz.StringGlarchMap = sgm;
txn.Commit();
s.Close();
s = OpenSession();
txn = s.BeginTransaction();
baz = (Baz) ((object[]) s.CreateQuery("select baz, baz from baz in class NHibernate.DomainModel.Baz").List()[0])[1];
Assert.AreEqual(1, baz.CascadingBars.Count, "baz.CascadingBars.Count");
Foo foo = new Foo();
s.Save(foo);
Foo foo2 = new Foo();
s.Save(foo2);
baz.FooArray = new Foo[] {foo, foo, null, foo2};
baz.FooSet.Add(foo);
baz.Customs.Add(new string[] {"new", "custom"});
baz.StringArray = null;
baz.StringList[0] = "new value";
baz.StringSet = new HashedSet();
// NOTE: We put two items in the map, but expect only one to come back, because
// of where="..." specified in the mapping for StringGlarchMap
Assert.AreEqual(1, baz.StringGlarchMap.Count, "baz.StringGlarchMap.Count");
IList list;
// disable this for dbs with no subselects
if (Dialect.SupportsSubSelects)
{
if (IsClassicParser)
{
list =
s.CreateQuery(
"select foo from foo in class NHibernate.DomainModel.Foo, baz in class NHibernate.DomainModel.Baz where foo in baz.FooArray.elements and 3 = some baz.IntArray.elements and 4 > all baz.IntArray.indices")
.List();
}
else
{
list =
s.CreateQuery(
"select foo from foo in class NHibernate.DomainModel.Foo, baz in class NHibernate.DomainModel.Baz where foo in elements(baz.FooArray) and 3 = some elements(baz.IntArray) and 4 > all indices(baz.IntArray)")
.List();
}
Assert.AreEqual(2, list.Count, "collection.elements find");
}
// sapdb doesn't like distinct with binary type
//if( !(dialect is Dialect.SAPDBDialect) )
//{
if (IsClassicParser)
{
list =
s.CreateQuery("select distinct foo from baz in class NHibernate.DomainModel.Baz, foo in baz.FooArray.elements").List
();
}
else
{
list =
s.CreateQuery("select distinct foo from baz
|
请发表评论