本文整理汇总了C#中DbConnection.Connect方法的典型用法代码示例。如果您正苦于以下问题:C# DbConnection.Connect方法的具体用法?C# DbConnection.Connect怎么用?C# DbConnection.Connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DbConnection
的用法示例。
在下文中一共展示了DbConnection.Connect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateVersionInfo
private static void CreateVersionInfo(DbConnection db)
{
using (var conn = db.Connect())
{
var sql = "CREATE TABLE `VersionInfo` (" +
"`Version` INTEGER NOT NULL, " +
"`AppliedOn` DATETIME DEFAULT CURRENT_TIMESTAMP, " +
"`Description` TEXT);";
conn.Execute(sql);
sql = "CREATE UNIQUE INDEX IF NOT EXISTS `UC_Version` ON `VersionInfo` (`Version` ASC);";
conn.Execute(sql);
}
}
示例2: MigrateToLatest
public void MigrateToLatest(DbConnection db)
{
var versionInfo = GetVersionInfo (db);
var currentVersion = versionInfo != null ? versionInfo.Version : 0;
using (var conn = db.Connect())
{
conn.BeginTransaction();
do
{
currentVersion++;
} while (MigrateToVersion(conn, currentVersion));
conn.Commit();
}
}
示例3: GetVersionInfo
protected static VersionInfo GetVersionInfo(DbConnection db)
{
using (var conn = db.Connect())
{
var sql = "SELECT Version FROM `VersionInfo` ORDER BY Version DESC LIMIT 1";
try
{
return conn.Query<VersionInfo>(sql).FirstOrDefault();
}
catch (Exception e)
{
if (!e.Message.Contains("no such table: VersionInfo"))
throw new Exception(e.Message, e);
CreateVersionInfo(db);
return conn.Query<VersionInfo>(sql).FirstOrDefault();
}
}
}