本文整理汇总了C#中OrmLiteConnectionFactory.Open方法的典型用法代码示例。如果您正苦于以下问题:C# OrmLiteConnectionFactory.Open方法的具体用法?C# OrmLiteConnectionFactory.Open怎么用?C# OrmLiteConnectionFactory.Open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OrmLiteConnectionFactory
的用法示例。
在下文中一共展示了OrmLiteConnectionFactory.Open方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Can_query_using_float_in_alernate_culuture
public void Can_query_using_float_in_alernate_culuture()
{
var dbFactory = new OrmLiteConnectionFactory(
GetFileConnectionString(),
FirebirdOrmLiteDialectProvider.Instance);
using (var db = dbFactory.Open())
{
db.CreateTable<Point>(true);
db.Insert(new Point { Width = 4, Height = 1.123f, Top = 3.456d, Left = 2.345m});
var points = db.Select<Point>();
Console.WriteLine(points.Dump());
Assert.That(points[0].Width, Is.EqualTo(4));
Assert.That(points[0].Height, Is.EqualTo(1.123f));
Assert.That(points[0].Top, Is.EqualTo(3.456d));
Assert.That(points[0].Left, Is.EqualTo(2.345m));
points = db.Select<Point>("Height={0}", 1.123f); // returns no rows! FirebirdSql bug?
Assert.That(points.Count>0);
}
}
示例2: SetUp
public void SetUp()
{
//Setup SQL Server Connection Factory
dbFactory = new OrmLiteConnectionFactory(
ConfigurationManager.ConnectionStrings["testDb"].ConnectionString,
MySqlDialectProvider.Instance);
using (var db = dbFactory.Open())
db.DropAndCreateTable<User>();
}
示例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
using (var db = dbFactory.Open())
db.CreateTable<MasterRecord>();
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
using (var db = dbFactory.Open(shardId))
db.CreateTable<Robot>();
});
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.Open()) //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);
}
}
}
}
示例4: Simple_Perf_test_using_InMemory_Sqlite
public void Simple_Perf_test_using_InMemory_Sqlite()
{
var dbFactory = new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider);
using (var db = dbFactory.Open())
{
db.DropAndCreateTable<TableWithStrings>();
var sw = Stopwatch.StartNew();
for (int i = 0; i < 100; i++)
{
var row = TableWithStrings.Create(i);
db.Insert(row);
}
"[:memory:] Time to INSERT 100 rows: {0}ms".Print(sw.ElapsedMilliseconds);
sw = Stopwatch.StartNew();
var rows = db.Select<TableWithStrings>();
"[:memory:] Time to SELECT {0} rows: {1}ms".Print(rows.Count, sw.ElapsedMilliseconds);
}
}