本文整理汇总了C#中SessionNoServer.OfType方法的典型用法代码示例。如果您正苦于以下问题:C# SessionNoServer.OfType方法的具体用法?C# SessionNoServer.OfType怎么用?C# SessionNoServer.OfType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SessionNoServer
的用法示例。
在下文中一共展示了SessionNoServer.OfType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateDataAndIterateSession
public void CreateDataAndIterateSession(int numObj)
{
using (SessionNoServer session = new SessionNoServer(systemDir))
{
session.BeginUpdate();
UInt32 dbNum = session.DatabaseNumberOf(typeof(NotSharingPage));
Database db = session.OpenDatabase(dbNum, true, false);
if (db != null)
session.DeleteDatabase(db);
dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeA));
db = session.OpenDatabase(dbNum, true, false);
if (db != null)
session.DeleteDatabase(db);
dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeB));
db = session.OpenDatabase(dbNum, true, false);
if (db != null)
session.DeleteDatabase(db);
session.Commit();
}
using (SessionNoServer session = new SessionNoServer(systemDir))
{
session.BeginUpdate();
UInt32 dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeB));
Placement place = new Placement(dbNum, 100);
for (int i = 0; i < numObj; i++)
{
NotSharingPage ns = new NotSharingPage();
session.Persist(ns);
SharingPageTypeA sA = new SharingPageTypeA();
session.Persist(sA);
SharingPageTypeB sB = new SharingPageTypeB();
if (i % 5 == 0)
sB.Persist(session, place);
else if (i % 1001 == 0)
sB.Persist(session, sA);
else if (i % 3001 == 0)
sB.Persist(session, ns);
else
session.Persist(sB);
}
session.Commit();
}
using (SessionNoServer session = new SessionNoServer(systemDir))
{
session.BeginRead();
UInt32 dbNum = session.DatabaseNumberOf(typeof(NotSharingPage));
Database db = session.OpenDatabase(dbNum);
AllObjects<NotSharingPage> all = session.AllObjects<NotSharingPage>(true, false);
OfType all2 = session.OfType(typeof(NotSharingPage), true, false);
dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeA));
Database dbA = session.OpenDatabase(dbNum);
dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeB));
Database dbB = session.OpenDatabase(dbNum);
AllObjects<SharingPageTypeA> allA = session.AllObjects<SharingPageTypeA>(true, false);
AllObjects<SharingPageTypeB> allB = session.AllObjects<SharingPageTypeB>(true, false);
int start = numObj / 2;
NotSharingPage ns = all.ElementAt(numObj - 1); // zero based index so deduct one
NotSharingPage ns2 = (NotSharingPage)all2.ElementAt(numObj - 1);
Assert.AreEqual(ns, ns2);
SharingPageTypeA sA = allA.ElementAt(15);
SharingPageTypeB sB = allB.ElementAt(10);
for (int i = start; i < numObj; i++)
ns = all.ElementAt(i);
//for (int i = start; i < numObj; i++)
// ns = all.Skip(i).T
//for (int i = start; i < numObj; i++)
// sA = allA.ElementAt(i);
all.Skip(100);
all2.Skip(100);
for (int i = start; i < numObj; i += 5)
{
ns = all.ElementAt(i);
ns2 = (NotSharingPage)all2.ElementAt(i);
Assert.AreEqual(ns, ns2);
}
for (int i = 5; i < 100; i += 5)
sB = allB.ElementAt(i);
for (int i = 0; i < numObj; i += 45000)
ns = all.ElementAt(i);
session.Commit();
session.BeginUpdate();
session.DeleteDatabase(db);
session.DeleteDatabase(dbA);
session.DeleteDatabase(dbB);
session.Commit();
}
}