本文整理汇总了C#中NHibernate.DomainModel.Category类的典型用法代码示例。如果您正苦于以下问题:C# Category类的具体用法?C# Category怎么用?C# Category使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Category类属于NHibernate.DomainModel命名空间,在下文中一共展示了Category类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindBySQLStar
public void FindBySQLStar()
{
ISession session = OpenSession();
Category s = new Category();
s.Name = nextLong.ToString();
nextLong++;
session.Save( s );
Simple simple = new Simple();
simple.Init();
session.Save( simple, nextLong++ );
A a = new A();
session.Save( a );
//B b = new B();
//session.Save( b );
session.CreateSQLQuery( "select {category.*} from Category {category}", "category", typeof( Category ) ).List();
session.CreateSQLQuery( "select {simple.*} from Simple {simple}", "simple", typeof( Simple ) ).List();
session.CreateSQLQuery( "select {a.*} from A {a}", "a", typeof( A ) ).List();
session.Delete( s );
session.Delete( simple );
session.Delete( a );
//session.Delete( b );
session.Flush();
session.Close();
}
示例2: CachedCollectionRefresh
public void CachedCollectionRefresh()
{
ISession s = OpenSession();
Category c = new Category();
IList list = new ArrayList();
c.Subcategories = list;
list.Add(new Category());
c.Name = "root";
object id = s.Save(c);
s.Flush();
s.Close();
s = OpenSession();
c = (Category) s.Load(typeof(Category), id);
NHibernateUtil.Initialize(c.Subcategories);
ISession ss = OpenSession();
Category c2 = (Category) ss.Load(typeof(Category), id);
ss.Delete(c2.Subcategories[0]);
c2.Subcategories.Clear();
ss.Flush();
ss.Close();
s.Refresh(c);
Assert.AreEqual(0, c.Subcategories.Count);
ss = OpenSession();
c2 = (Category) ss.Load(typeof(Category), id);
c2.Subcategories.Add(new Category());
c2.Subcategories.Add(new Category());
ss.Flush();
ss.Close();
s.Refresh(c);
Assert.AreEqual(2, c.Subcategories.Count);
s.Flush();
s.Close();
s = OpenSession();
c = (Category) s.Load(typeof(Category), id);
Assert.AreEqual(2, c.Subcategories.Count);
s.Delete(c);
s.Flush();
s.Close();
}
示例3: CopyCascade
public void CopyCascade()
{
ISession s = OpenSession();
Category child = new Category();
child.Name = "child";
s.Save(child);
s.Flush();
s.Close();
s = OpenSession();
Category parent = new Category();
parent.Name = "parent";
parent.Subcategories.Add(child);
child.Name = "child2";
// Save parent and cascade update detached child
Category persistentParent = s.Merge(parent);
Assert.IsTrue(persistentParent.Subcategories.Count == 1);
Assert.AreEqual(((Category) persistentParent.Subcategories[0]).Name, "child2");
s.Flush();
s.Close();
s = OpenSession();
s.Delete(persistentParent);
s.Flush();
s.Close();
}
示例4: PolymorphicCriteria
public void PolymorphicCriteria()
{
ISession s = OpenSession();
ITransaction txn = s.BeginTransaction();
Category f = new Category();
Single b = new Single();
b.Id = "asdfa";
b.String = "asdfasdf";
s.Save(f);
s.Save(b);
IList list = s.CreateCriteria(typeof(object)).List();
Assert.AreEqual(2, list.Count);
Assert.IsTrue(list.Contains(f));
Assert.IsTrue(list.Contains(b));
s.Delete(f);
s.Delete(b);
txn.Commit();
s.Close();
}
示例5: QueuedBagAdds
public void QueuedBagAdds()
{
ISession s = OpenSession();
Assignable a = new Assignable();
a.Id = "foo";
a.Categories = new ArrayList();
Category c = new Category();
c.Assignable = a;
a.Categories.Add(c);
s.Save(a);
s.Flush();
s.Close();
sessions.EvictCollection("NHibernate.DomainModel.Assignable.Categories");
s = OpenSession();
a = (Assignable) s.Get(typeof(Assignable), "foo");
c = new Category();
c.Assignable = a;
a.Categories.Add(c);
Assert.IsFalse(NHibernateUtil.IsInitialized(a.Categories));
Assert.AreEqual(2, a.Categories.Count);
s.Flush();
s.Close();
sessions.EvictCollection("NHibernate.DomainModel.Assignable.Categories");
s = OpenSession();
a = (Assignable) s.Get(typeof(Assignable), "foo");
c = new Category();
c.Assignable = a;
a.Categories.Add(c);
Assert.IsFalse(NHibernateUtil.IsInitialized(a.Categories));
s.Flush();
Assert.IsFalse(NHibernateUtil.IsInitialized(a.Categories));
Assert.AreEqual(3, a.Categories.Count);
s.Close();
sessions.EvictCollection("NHibernate.DomainModel.Assignable.Categories");
s = OpenSession();
a = (Assignable) s.Get(typeof(Assignable), "foo");
Assert.AreEqual(3, a.Categories.Count);
s.Delete(a);
s.Flush();
s.Close();
}
示例6: CollectionRefresh
public void CollectionRefresh()
{
ISession s = OpenSession();
Category c = new Category();
IList list = new ArrayList();
c.Subcategories = list;
list.Add(new Category());
c.Name = "root";
object id = s.Save(c);
s.Flush();
s.Close();
s = OpenSession();
c = (Category) s.Load(typeof(Category), id);
s.Refresh(c);
s.Flush();
Assert.AreEqual(1, c.Subcategories.Count);
s.Flush();
s.Close();
s = OpenSession();
c = (Category) s.Load(typeof(Category), id);
Assert.AreEqual(1, c.Subcategories.Count);
// modify the collection in another session
ISession s2 = OpenSession();
Category c2 = (Category) s2.Load(typeof(Category), id);
c2.Subcategories.Add(new Category());
s2.Flush();
s2.Close();
// now lets refresh the collection and see if it picks up
// the new objects
s.Refresh(c);
Assert.AreEqual(2, c.Subcategories.Count, "should have gotten the addition from s2");
s.Delete(c);
s.Flush();
s.Close();
}
示例7: PolymorphicCriteria
public void PolymorphicCriteria()
{
ISession s = OpenSession();
Category f = new Category();
DomainModel.Single b = new DomainModel.Single();
b.Id = "asdfa";
b.String = "asdfasdf";
s.Save( f );
s.Save( b );
IList list = s.CreateCriteria( typeof( object )).List();
Assert.AreEqual( 2, list.Count );
Assert.IsTrue( list.Contains( f ) );
Assert.IsTrue( list.Contains( b ) );
s.Delete( f );
s.Delete( b );
s.Flush();
s.Close();
}
示例8: Categories
public void Categories()
{
Category c = new Category();
c.Name = Category.RootCategory;
Category c1 = new Category();
Category c2 = new Category();
Category c3 = new Category();
c.Subcategories.Add(c1);
c.Subcategories.Add(c2);
c2.Subcategories.Add(null);
c2.Subcategories.Add(c3);
using (ISession s = OpenSession())
{
s.Save(c);
s.Flush();
}
using (ISession s = OpenSession())
{
c = (Category) s.Load(typeof(Category), c.Id);
Assert.IsNotNull(c.Subcategories[0]);
Assert.IsNotNull(c.Subcategories[1]);
IList list = ((Category) c.Subcategories[1]).Subcategories;
Assert.IsNull(list[0]);
Assert.IsNotNull(list[1]);
IEnumerator enumer =
s.CreateQuery("from c in class Category where c.Name = NHibernate.DomainModel.Category.RootCategory").Enumerable().
GetEnumerator();
Assert.IsTrue(enumer.MoveNext());
}
using (ISession s = OpenSession())
{
s.Delete("from Category");
s.Flush();
}
}
示例9: FindBySQLParameters
public void FindBySQLParameters()
{
ISession s = OpenSession();
Category c = new Category();
c.Name = "Good";
Assignable assn = new Assignable();
assn.Id = "i.d.";
IList l = new ArrayList();
l.Add(c);
assn.Categories = l;
c.Assignable = assn;
s.Save(assn);
s.Flush();
c = new Category();
c.Name = "Best";
assn = new Assignable();
assn.Id = "i.d.2";
l = new ArrayList();
l.Add(c);
assn.Categories = l;
c.Assignable = assn;
s.Save(assn);
s.Flush();
c = new Category();
c.Name = "Better";
assn = new Assignable();
assn.Id = "i.d.7";
l = new ArrayList();
l.Add(c);
assn.Categories = l;
c.Assignable = assn;
s.Save(assn);
s.Flush();
assn = new Assignable();
assn.Id = "i.d.3";
s.Save(assn);
s.Flush();
s.Close();
s = OpenSession();
IQuery basicParam = s.CreateSQLQuery("select {category.*} from Category {category} where {category}.Name = 'Best'", "category", typeof( Category ));
IList list = basicParam.List();
Assert.AreEqual(1, list.Count);
IQuery unnamedParam = s.CreateSQLQuery("select {category.*} from Category {category} where {category}.Name = ? or {category}.Name = ?", "category", typeof( Category ));
unnamedParam.SetString(0, "Good");
unnamedParam.SetString(1, "Best");
list = unnamedParam.List();
Assert.AreEqual(2, list.Count);
IQuery namedParam = s.CreateSQLQuery("select {category.*} from Category {category} where ({category}.Name=:firstCat or {category}.Name=:secondCat)", "category", typeof( Category ));
namedParam.SetString("firstCat", "Better");
namedParam.SetString("secondCat", "Best");
list = namedParam.List();
Assert.AreEqual(2, list.Count);
s.Delete("from Assignable");
s.Delete("from Category");
s.Flush();
s.Close();
}
示例10: FindBySQLMultipleObject
public void FindBySQLMultipleObject()
{
ISession s = OpenSession();
Category c = new Category();
c.Name = "NAME";
Assignable assn = new Assignable();
assn.Id = "i.d.";
IList l = new ArrayList();
l.Add( c );
assn.Categories = l;
c.Assignable = assn;
s.Save( assn );
s.Flush();
c = new Category();
c.Name = "NAME2";
assn = new Assignable();
assn.Id = "i.d.2";
l = new ArrayList();
l.Add( c );
assn.Categories = l;
c.Assignable = assn;
s.Save( assn );
s.Flush();
assn = new Assignable();
assn.Id = "i.d.3";
s.Save( assn );
s.Flush();
s.Close();
s = OpenSession();
if ( !(dialect is Dialect.MySQLDialect) )
{
IList list = s.CreateSQLQuery( "select {category.*}, {assignable.*} from Category {category}, \"assign able\" {assignable}", new string[] { "category", "assignable" }, new System.Type[] { typeof( Category ), typeof( Assignable ) } ).List();
Assert.AreEqual( 6, list.Count, "Count differs" ); // cross-product of 2 categories x 3 assignables;
Assert.IsTrue( list[0] is object[] );
}
s.Delete( "from Assignable" );
s.Delete( "from Category" );
s.Flush();
s.Close();
}
示例11: FindBySQLAssociatedObject
public void FindBySQLAssociatedObject()
{
ISession s = OpenSession();
Category c = new Category();
c.Name = "NAME";
Assignable assn = new Assignable();
assn.Id = "i.d.";
IList l = new ArrayList();
l.Add( c );
assn.Categories = l;
c.Assignable = assn;
s.Save( assn );
s.Flush();
s.Close();
s = OpenSession();
IList list = s.CreateSQLQuery( "select {category.*} from Category {category}", "category", typeof( Category ) ).List();
Assert.AreEqual( 1, list.Count, "Count differs" );
s.Delete( "from Assignable" );
s.Delete( "from Category" );
s.Flush();
s.Close();
}
示例12: FindBySQLProperties
public void FindBySQLProperties()
{
ISession session = OpenSession();
Category s = new Category();
s.Name = nextLong.ToString();
nextLong++;
session.Save( s );
s = new Category();
s.Name = "WannaBeFound";
session.Flush();
IQuery query = session.CreateSQLQuery( "select {category.*} from Category {category} where {category}.Name = :Name", "category", typeof( Category ) );
query.SetProperties( s );
query.List();
session.Delete( "from Category" );
session.Flush();
session.Close();
}
示例13: FindBySQLMultipleObject
public void FindBySQLMultipleObject()
{
ISession s = OpenSession();
Category c = new Category();
c.Name = "NAME";
Assignable assn = new Assignable();
assn.Id = "i.d.";
assn.Categories = new List<Category> {c};
c.Assignable = assn;
s.Save(assn);
s.Flush();
c = new Category();
c.Name = "NAME2";
assn = new Assignable();
assn.Id = "i.d.2";
assn.Categories = new List<Category> { c };
c.Assignable = assn;
s.Save(assn);
s.Flush();
assn = new Assignable();
assn.Id = "i.d.3";
s.Save(assn);
s.Flush();
s.Close();
s = OpenSession();
if (!(Dialect is MySQLDialect))
{
IList list =
s.CreateSQLQuery("select {category.*}, {assignable.*} from Category {category}, \"assign able\" {assignable}")
.AddEntity("category", typeof(Category))
.AddEntity("assignable", typeof(Assignable))
.List();
Assert.AreEqual(6, list.Count, "Count differs"); // cross-product of 2 categories x 3 assignables;
Assert.IsTrue(list[0] is object[]);
}
s.Delete("from Assignable");
s.Delete("from Category");
s.Flush();
s.Close();
}
示例14: CollectionReplace2
public void CollectionReplace2()
{
ISession s = OpenSession();
ITransaction t = s.BeginTransaction();
Category c = new Category();
IList<Category> list = new List<Category>();
c.Subcategories = list;
list.Add(new Category());
Category c2 = new Category();
s.Save(c2);
s.Save(c);
t.Commit();
s.Close();
s = OpenSession();
t = s.BeginTransaction();
c = (Category) s.Load(typeof(Category), c.Id, LockMode.Upgrade);
IList<Category> list2 = c.Subcategories;
t.Commit();
s.Close();
s = OpenSession();
t = s.BeginTransaction();
c2 = (Category) s.Load(typeof(Category), c2.Id, LockMode.Upgrade);
c2.Subcategories = list2;
t.Commit();
s.Close();
s = OpenSession();
t = s.BeginTransaction();
c2 = (Category) s.Load(typeof(Category), c2.Id, LockMode.Upgrade);
Assert.AreEqual(1, c2.Subcategories.Count);
s.Delete(c2);
s.Delete(s.Load(typeof(Category), c.Id));
t.Commit();
s.Close();
}
示例15: Copy
public void Copy()
{
Category catWA = new Category();
catWA.Name = "HSQL workaround";
Category cat = new Category();
cat.Name = "foo";
Category subCatBar = new Category();
subCatBar.Name = "bar";
Category subCatBaz = new Category();
subCatBaz.Name = "baz";
cat.Subcategories.Add( subCatBar );
cat.Subcategories.Add( subCatBaz );
using( ISession s = OpenSession() )
{
s.Save( catWA );
s.Save( cat );
s.Flush();
}
cat.Name = "new foo";
subCatBar.Name = "new bar";
cat.Subcategories.Remove( subCatBaz );
Category newCat = new Category();
newCat.Name = "new";
cat.Subcategories.Add( newCat );
Category newSubCat = new Category();
newSubCat.Name = "new sub";
newCat.Subcategories.Add( newSubCat );
using( ISession s = OpenSession() )
{
s.SaveOrUpdateCopy( cat );
s.Flush();
}
using( ISession s = OpenSession() )
{
cat = (Category) s.CreateQuery( "from Category cat where cat.Name='new foo'").UniqueResult();
newSubCat = (Category) s.CreateQuery( "from Category cat where cat.Name='new sub'").UniqueResult();
newSubCat.Subcategories.Add( cat );
subCatBaz = (Category) s.SaveOrUpdateCopy( newSubCat, subCatBaz.Id );
Assert.IsTrue( subCatBaz.Name.Equals( "new sub" ) );
Assert.IsTrue( subCatBaz.Subcategories.Count == 1 && subCatBaz.Subcategories[0] == cat );
newSubCat.Subcategories.Remove( cat );
s.Delete( cat );
s.Delete( subCatBaz );
s.Delete( catWA );
s.Flush();
}
}