本文整理汇总了C#中OrmLiteConnectionFactory.Run方法的典型用法代码示例。如果您正苦于以下问题:C# OrmLiteConnectionFactory.Run方法的具体用法?C# OrmLiteConnectionFactory.Run怎么用?C# OrmLiteConnectionFactory.Run使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OrmLiteConnectionFactory
的用法示例。
在下文中一共展示了OrmLiteConnectionFactory.Run方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetUp
public void SetUp()
{
//Setup SQL Server Connection Factory
dbFactory = new OrmLiteConnectionFactory(
"~/App_Data/Database1.mdf".MapAbsolutePath(),
SqlServerOrmLiteDialectProvider.Instance);
dbFactory.Run(db => db.CreateTable<User>(overwrite: true));
}
示例2: SetUp
public void SetUp()
{
//Setup SQL Server Connection Factory
dbFactory = new OrmLiteConnectionFactory(
ConfigurationManager.ConnectionStrings["testDb"].ConnectionString,
MySqlDialectProvider.Instance);
dbFactory.Run(db => db.CreateTable<User>(overwrite: true));
}
示例3: Shard_1000_Robots_over_10_shards
public void Shard_1000_Robots_over_10_shards()
{
const int NoOfShards = 10;
const int NoOfRobots = 1000;
var dbFactory = new OrmLiteConnectionFactory(
"~/App_Data/robots-master.sqlite".MapAbsolutePath(),
false, SqliteDialect.Provider);
//var dbFactory = new OrmLiteConnectionFactory(
// "Data Source=localhost;Initial Catalog=RobotsMaster;Integrated Security=SSPI",
// SqlServerDialect.Provider);
//Create Master Table in Master DB
dbFactory.Run(db => db.CreateTable<MasterRecord>(overwrite: false));
NoOfShards.Times(i =>
{
var shardId = "robots-shard" + i;
dbFactory.RegisterConnection(shardId, "~/App_Data/{0}.sqlite".Fmt(shardId).MapAbsolutePath(),
SqliteDialect.Provider);
//Create Robot table in Shard
dbFactory.OpenDbConnection(shardId).Run(db => db.CreateTable<Robot>(overwrite: false));
});
var newRobots = NoOfRobots.Times(i => //Create 1000 Robots
new Robot
{
Id = i,
Name = "R2D" + i,
CreatedDate = DateTime.UtcNow,
CellCount = DateTime.UtcNow.ToUnixTimeMs()%100000
});
foreach (var newRobot in newRobots)
{
using (IDbConnection db = dbFactory.OpenDbConnection()) //Open Connection to Master DB
{
db.Insert(new MasterRecord {Id = Guid.NewGuid(), RobotId = newRobot.Id, RobotName = newRobot.Name});
using (IDbConnection robotShard = dbFactory.OpenDbConnection("robots-shard" + newRobot.Id%NoOfShards)) //Shard DB
{
robotShard.Insert(newRobot);
}
}
}
}