本文整理汇总了C#中Domain.OpenSession方法的典型用法代码示例。如果您正苦于以下问题:C# Domain.OpenSession方法的具体用法?C# Domain.OpenSession怎么用?C# Domain.OpenSession使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Domain
的用法示例。
在下文中一共展示了Domain.OpenSession方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Setup
protected override void Setup()
{
var config = DomainConfiguration.Load("mssql2005");
config.Sessions.Add(new SessionConfiguration("Default"));
// config.Sessions.Default.CacheType = SessionCacheType.LruWeak;
config.Sessions.Default.CacheType = SessionCacheType.Infinite;
config.Types.Register(typeof(Simplest).Assembly, typeof(Simplest).Namespace);
domain = Domain.Build(config);
using (var session = domain.OpenSession())
using (var ts = session.OpenTransaction()) {
var query = session.Query.Execute(qe => qe.All<Simplest>());
foreach (var o in query)
o.Remove();
ts.Complete();
}
}
示例2: NorthwindContext
public NorthwindContext(Domain domain)
{
session = domain.OpenSession();
transactionScope = session.OpenTransaction();
}
示例3: Fill
public static void Fill(Domain domain)
{
con.Open();
SqlTransaction transaction = con.BeginTransaction();
SqlCommand cmd = con.CreateCommand();
cmd.Transaction = transaction;
cmd.CommandText = "Select * from [dbo].[Categories]";
var reader = cmd.ExecuteReader();
using (var session = domain.OpenSession())
using (var tr = session.OpenTransaction())
{
#region Categories
var categories = new Dictionary<object, Category>();
while (reader.Read())
{
var category = new Category(session);
for (int i = 1; i < reader.FieldCount; i++)
category[reader.GetName(i)] = !reader.IsDBNull(i) ? reader.GetValue(i) : null;
categories.Add(reader.GetValue(0), category);
}
reader.Close();
#endregion
#region Customers
var customers = new Dictionary<object, Customer>();
cmd.CommandText = "Select * from [dbo].[Customers]";
reader = cmd.ExecuteReader();
while (reader.Read())
{
var customer = new Customer(session, reader.GetString(0));
for (int i = 1; i < reader.FieldCount; i++)
customer[reader.GetName(i)] = !reader.IsDBNull(i) ? reader.GetValue(i) : null;
customers.Add(reader.GetValue(0), customer);
}
reader.Close();
#endregion
#region Regions
var regions = new Dictionary<object, Region>();
cmd.CommandText = "Select * from [dbo].[Region]";
reader = cmd.ExecuteReader();
while (reader.Read())
{
var region = new Region(session);
for (int i = 1; i < reader.FieldCount; i++)
region[reader.GetName(i)] = !reader.IsDBNull(i) ? reader.GetValue(i) : null;
regions.Add(reader.GetValue(0), region);
}
reader.Close();
#endregion
#region Suppliers
var suppliers = new Dictionary<object, Supplier>();
cmd.CommandText = "Select * from [dbo].[Suppliers]";
reader = cmd.ExecuteReader();
while (reader.Read()) {
var supplier = new Supplier(session);
for (int i = 1; i < reader.FieldCount; i++)
supplier[reader.GetName(i)] = !reader.IsDBNull(i) ? reader.GetValue(i) : null;
suppliers.Add(reader.GetValue(0), supplier);
}
reader.Close();
#endregion
#region Shippers
var shippers = new Dictionary<object, Shipper>();
cmd.CommandText = "Select * from [dbo].[Shippers]";
reader = cmd.ExecuteReader();
while (reader.Read())
{
var shipper = new Shipper(session);
for (int i = 1; i < reader.FieldCount; i++)
shipper[reader.GetName(i)] = !reader.IsDBNull(i) ? reader.GetValue(i) : null;
shippers.Add(reader.GetValue(0), shipper);
}
reader.Close();
#endregion
#region Products
var products = new Dictionary<object, Product>();
cmd.CommandText = "Select * from [dbo].[Products]";
reader = cmd.ExecuteReader(CommandBehavior.KeyInfo);
while (reader.Read())
{
var discontinuedColumnIndex = reader.GetOrdinal("Discontinued");
Product product = reader.GetBoolean(discontinuedColumnIndex)
? (Product) new DiscontinuedProduct(session)
: new ActiveProduct(session);
//.........这里部分代码省略.........