本文整理汇总了C#中IDbConnectionFactory.Open方法的典型用法代码示例。如果您正苦于以下问题:C# IDbConnectionFactory.Open方法的具体用法?C# IDbConnectionFactory.Open怎么用?C# IDbConnectionFactory.Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDbConnectionFactory
的用法示例。
在下文中一共展示了IDbConnectionFactory.Open方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnBeforeEachTest
public override void OnBeforeEachTest()
{
base.OnBeforeEachTest();
this.Container.Register<IDbConnectionFactory>(c =>
new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider));
this.DbFactory = this.Container.Resolve<IDbConnectionFactory>();
using (var db = DbFactory.Open())
db.DropAndCreateTable<Movie>();
}
示例2: Database
/// <summary>
/// Set to true to recreate the database (losing all data)
/// </summary>
/// <param name="clean"></param>
/// <param name="connectionString"></param>
public Database(bool clean = false, string connectionString = null)
{
_connectionFactory = new OrmLiteConnectionFactory(connectionString, SqliteDialect.Provider);
using (var db = _connectionFactory.Open())
{
var models = new[]
{
typeof(Device),
typeof(Sensor),
typeof(StringReading),
typeof(DecimalReading),
typeof(BlobReading),
typeof(User),
typeof(Session),
typeof(Claim),
};
if (clean)
{
foreach (var model in models)
db.CreateTable(true, model);
using (var transaction = db.OpenTransaction())
{
//Create admin user with null password
var admin = new User(DEFAULT_ADMINISTRATOR_USERNAME, DEFAULT_ADMINISTRATOR_PASSWORD);
db.Save(admin);
//Create some sensible claims for an admin user
string[] claims = {
"superuser"
};
foreach (var claim in claims)
db.Save(new Claim(admin, claim));
transaction.Commit();
}
}
else
{
foreach (var model in models)
db.CreateTableIfNotExists(model);
}
}
}
示例3: TestInitialize
public void TestInitialize()
{
Container = new Container();
Container.Register<IDbConnectionFactory>(
new OrmLiteConnectionFactory(":memory:", false, SqliteDialect.Provider));
DbFactory = Container.Resolve<IDbConnectionFactory>();
using (var db = DbFactory.Open())
{
db.CreateTable<Customer>(overwrite: true);
db.Insert(new Customer
{
FirstName = "Sanjay",
LastName = "Uttam"
});
}
}
示例4: MetroiLinksService
public MetroiLinksService(IDbConnectionFactory dbConnectionFactory)
{
Repository = new OrmLiteRepository<MetroiLinks>(dbConnectionFactory.Open());
}
示例5: ClientsService
public ClientsService(IDbConnectionFactory dbConnectionFactory)
{
Repository = new OrmLiteRepository<Client>(dbConnectionFactory.Open());
}
示例6: FolderService
public FolderService(IDbConnectionFactory dbConnectionFactory)
{
Repository = new OrmLiteRepository<Folder>(dbConnectionFactory.Open());
}