本文整理汇总了C#中Session.OpenTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# Session.OpenTransaction方法的具体用法?C# Session.OpenTransaction怎么用?C# Session.OpenTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Session
的用法示例。
在下文中一共展示了Session.OpenTransaction方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateNodesAndSubnodes
public void CreateNodesAndSubnodes()
{
Store store = new Store("xmlfs5");
Workspace workspace = new Workspace(store, "ws");
Session session = new Session(workspace);
INode root = session.Workspace.RootNode;
using (var tr = session.OpenTransaction())
{
for (int k = 1; k <= 10; k++)
{
INode node = session.CreateNode(root, "node" + k, new Property[] {
new Property("Value", k)
});
for (int j = 1; j <= 10; j++)
session.CreateNode(node, "subnode" + j, new Property[] {
new Property("ParentValue", k),
new Property("Value", j)
});
}
tr.Complete();
}
for (int k = 1; k <= 10; k++)
{
Assert.IsTrue(File.Exists("xmlfs5/node" + k + ".xml"));
Assert.AreEqual(k, store.LoadProperties("/node" + k)["Value"].Value);
for (int j = 1; j <= 10; j++)
{
Assert.IsTrue(File.Exists("xmlfs5/node" + k + "/subnode" + j + ".xml"));
var properties = store.LoadProperties("/node" + k + "/subnode" + j);
Assert.AreEqual(k, properties["ParentValue"].Value);
Assert.AreEqual(j, properties["Value"].Value);
}
}
}
示例2: CreateNodes
public void CreateNodes()
{
Store store = new Store("xmlfs4");
Workspace workspace = new Workspace(store, "ws");
Session session = new Session(workspace);
INode root = session.Workspace.RootNode;
using (var tr = session.OpenTransaction())
{
for (int k = 1; k <= 10; k++)
session.CreateNode(root, "node" + k, new Property[] {
new Property("Value", k)
});
tr.Complete();
}
for (int k = 1; k <= 10; k++)
{
Assert.IsTrue(File.Exists("xmlfs4/node" + k + ".xml"));
Assert.AreEqual(k, store.LoadProperties("/node" + k)["Value"].Value);
}
}
示例3: NorthwindContext
public NorthwindContext(Domain domain)
{
session = domain.OpenSession();
transactionScope = session.OpenTransaction();
}
示例4: CreateNodesAndSubnodesRemoveNodes
public void CreateNodesAndSubnodesRemoveNodes()
{
Store store = new Store("xmlfs6");
Workspace workspace = new Workspace(store, "ws");
Session session = new Session(workspace);
INode root = session.Workspace.RootNode;
using (var tr = session.OpenTransaction())
{
for (int k = 1; k <= 10; k++)
{
INode node = session.CreateNode(root, "node" + k, new Property[] {
new Property("Value", k)
});
for (int j = 1; j <= 10; j++)
session.CreateNode(node, "subnode" + j, new Property[] {
new Property("ParentValue", k),
new Property("Value", j)
});
}
tr.Complete();
}
using (var tr = session.OpenTransaction())
{
for (int k = 1; k <= 10; k++)
session.RemoveNode(root.ChildNodes["node" + k]);
tr.Complete();
}
for (int k = 1; k <= 10; k++)
Assert.IsFalse(File.Exists("xmlfs6/node" + k + ".xml"));
}
示例5: SetPropertyValueAndRollback
public void SetPropertyValueAndRollback()
{
Store store = new Store("xmlfs2");
Workspace workspace = new Workspace(store, "ws");
Session session = new Session(workspace);
INode node = session.Workspace.RootNode;
using (var tr = session.OpenTransaction())
{
node["Name"] = "Adam";
Assert.AreEqual("Adam", node["Name"]);
}
PropertyList properties = store.LoadProperties("/");
Assert.AreEqual("Root", properties["Name"].Value);
}
示例6: RemoveExistingNode
public void RemoveExistingNode()
{
Store store = new Store("xmlfs3");
Workspace workspace = new Workspace(store, "ws");
Session session = new Session(workspace);
INode node = session.Workspace.RootNode;
Assert.IsTrue(Directory.Exists("xmlfs3/father"));
Assert.IsTrue(File.Exists("xmlfs3/father.xml"));
using (var tr = session.OpenTransaction())
{
session.RemoveNode(node.ChildNodes["father"]);
tr.Complete();
}
Assert.IsFalse(Directory.Exists("xmlfs3/father"));
Assert.IsFalse(File.Exists("xmlfs3/father.xml"));
}