本文整理汇总了C#中IDbConnectionFactory.OpenDbConnection方法的典型用法代码示例。如果您正苦于以下问题:C# IDbConnectionFactory.OpenDbConnection方法的具体用法?C# IDbConnectionFactory.OpenDbConnection怎么用?C# IDbConnectionFactory.OpenDbConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDbConnectionFactory
的用法示例。
在下文中一共展示了IDbConnectionFactory.OpenDbConnection方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Init
public static void Init(IDbConnectionFactory connectionFactory)
{
try
{
using (var db = connectionFactory.OpenDbConnection())
{
db.DropAndCreateTable<RestMovie>();
db.SaveAll(Top5Movies);
}
}
catch (Exception)
{
throw;
}
}
开发者ID:grammarware,项目名称:fodder,代码行数:15,代码来源:tests_ServiceStack_WebHost_Endpoints_Tests_IntegrationTests_ConfigureDatabase.cs
示例2: SetUp
public new void SetUp()
{
testServer = new RainyTestServer ();
if (dbScenario == "postgres") {
testServer.ScenarioPostgres ();
} else if (dbScenario == "sqlite" || string.IsNullOrEmpty (dbScenario)) {
testServer.ScenarioSqlite ();
}
testServer.Start ();
this.connFactory = RainyTestServer.Container.Resolve<IDbConnectionFactory> ();
using (var db = connFactory.OpenDbConnection ()) {
testUser = db.First<DBUser> (u => u.Username == RainyTestServer.TEST_USER);
}
}
示例3: Init
public static void Init(IDbConnectionFactory connectionFactory)
{
try
{
using (var dbConn = connectionFactory.OpenDbConnection())
using (var dbCmd = dbConn.CreateCommand())
{
dbCmd.CreateTable<Todo>(true);
dbCmd.SaveAll(Todos);
}
}
catch (Exception)
{
throw;
}
}
示例4: Init
public static void Init(IDbConnectionFactory connectionFactory)
{
try
{
using (var dbConn = connectionFactory.OpenDbConnection())
using (var dbCmd = dbConn.CreateCommand())
{
dbCmd.CreateTable<Movie>(false);
dbCmd.SaveAll(Top5Movies);
}
}
catch (Exception ex)
{
throw;
}
}
示例5: Init
public static void Init(IDbConnectionFactory connectionFactory)
{
try
{
using (var dbConn = connectionFactory.OpenDbConnection())
{
dbConn.CreateTable<User>(false);
dbConn.CreateTable<Movie>(false);
dbConn.CreateTable<Logger>(false);
dbConn.SaveAll(Top5Movies); //insert or update the Top5Movies
}
}
catch (Exception ex)
{
throw ex;
}
}
示例6: DbStorage
public DbStorage(IDbConnectionFactory factory, string username, bool use_history = true)
{
if (factory == null)
throw new ArgumentNullException ("factory");
this.connFactory = factory;
using (var dbu = connFactory.OpenDbConnection ()) {
this.User = dbu.Select<DBUser> (u => u.Username == username)[0];
}
this.Manifest = this.User.Manifest;
this.UseHistory = use_history;
db = factory.OpenDbConnection ();
// start everything as a transaction
trans = db.BeginTransaction ();
}
示例7: DbStorage
public DbStorage(IDbConnectionFactory factory, string username, SyncManifest manifest, bool use_history = true)
{
if (factory == null)
throw new ArgumentNullException ("factory");
this.connFactory = factory;
if (string.IsNullOrEmpty (username))
this.Username = "default";
else
this.Username = username;
this.Manifest = manifest;
this.UseHistory = use_history;
db = factory.OpenDbConnection ();
// start everything as a transaction
trans = db.BeginTransaction ();
}
示例8: CreateSchema
public static void CreateSchema(IDbConnectionFactory connFactory, bool reset = false)
{
if (connFactory == null)
throw new ArgumentNullException ("connFactory");
using (var db = connFactory.OpenDbConnection ()) {
if (reset) {
// postgresql ormlite workaround
var ormfac = connFactory as OrmLiteConnectionFactory;
if (ormfac.DialectProvider == PostgreSqlDialect.Provider) {
try {
var cmd = db.CreateCommand ();
cmd.CommandText = "DROP SCHEMA IF EXISTS PUBLIC CASCADE;";
cmd.ExecuteNonQuery ();
cmd = db.CreateCommand ();
cmd.CommandText = "CREATE SCHEMA public AUTHORIZATION rainy";
cmd.ExecuteNonQuery ();
} catch (Exception e) {
Console.WriteLine (e.Message);
}
db.CreateTableIfNotExists <DBUser> ();
db.CreateTableIfNotExists <DBNote> ();
db.CreateTableIfNotExists <DBArchivedNote> ();
db.CreateTableIfNotExists <DBAccessToken> ();
db.CreateTableIfNotExists <DBRequestToken> ();
} else {
db.DropAndCreateTable <DBUser> ();
db.DropAndCreateTable <DBNote> ();
db.DropAndCreateTable <DBArchivedNote> ();
db.DropAndCreateTable <DBAccessToken> ();
db.DropAndCreateTable <DBRequestToken> ();
}
} else {
db.CreateTableIfNotExists <DBUser> ();
db.CreateTableIfNotExists <DBNote> ();
db.CreateTableIfNotExists <DBArchivedNote> ();
db.CreateTableIfNotExists <DBAccessToken> ();
db.CreateTableIfNotExists <DBRequestToken> ();
}
}
}
示例9: SeedStackOverflowData
private void SeedStackOverflowData(IDbConnectionFactory dbConnectionFactory)
{
var client = new JsonServiceClient();
int numberOfPages = 80;
int pageSize = 100;
var dbQuestions = new List<Question>();
var dbAnswers = new List<Answer>();
try
{
for (int i = 1; i < numberOfPages + 1; i++)
{
//Throttle queries
Thread.Sleep(100);
var questionsResponse =
client.Get("https://api.stackexchange.com/2.2/questions?page={0}&pagesize={1}&site={2}&tagged=servicestack"
.Fmt(i, pageSize, "stackoverflow"));
QuestionsResponse qResponse;
using (new ConfigScope())
{
var json = questionsResponse.ReadToEnd();
qResponse = json.FromJson<QuestionsResponse>();
dbQuestions.AddRange(qResponse.Items.Select(q => q.ConvertTo<Question>()));
}
var acceptedAnswers =
qResponse.Items
.Where(x => x.AcceptedAnswerId != null)
.Select(x => x.AcceptedAnswerId).ToList();
var answersResponse = client.Get("https://api.stackexchange.com/2.2/answers/{0}?sort=activity&site=stackoverflow"
.Fmt(acceptedAnswers.Join(";")));
using (new ConfigScope())
{
var json = answersResponse.ReadToEnd();
var aResponse = JsonSerializer.DeserializeFromString<AnswersResponse>(json);
dbAnswers.AddRange(aResponse.Items.Select(a => a.ConvertTo<Answer>()));
}
}
}
catch (Exception ex)
{
//ignore
}
//Filter duplicates
dbQuestions = dbQuestions.GroupBy(q => q.QuestionId).Select(q => q.First()).ToList();
dbAnswers = dbAnswers.GroupBy(a => a.AnswerId).Select(a => a.First()).ToList();
var questionTags = dbQuestions.SelectMany(q =>
q.Tags.Select(t => new QuestionTag { QuestionId = q.QuestionId, Tag = t }));
using (var db = dbConnectionFactory.OpenDbConnection())
{
db.InsertAll(dbQuestions);
db.InsertAll(dbAnswers);
db.InsertAll(questionTags);
}
}
示例10: CreateSqliteInMemoryTables
private void CreateSqliteInMemoryTables(IDbConnectionFactory dbFactory)
{
try
{
using (IDbConnection db = dbFactory.OpenDbConnection())
{
db.CreateTable<Todo>(true);
db.CreateTable<Account>(false);
db.CreateTable<Service>(false);
db.CreateTable<Tag>(false);
db.CreateTable<Content>(false);
db.CreateTable<ContentTag>(false);
Guid accountId = Guid.NewGuid();
Guid serviceId = Guid.NewGuid();
db.Insert<Todo>(new Todo { Id = Guid.NewGuid(), Content = "bla", Done = false, Order = 1 });
db.Insert<Account>(new Account { Id = accountId, FullName = "Metaintellect" });
db.Insert<Service>(new Service { Id = serviceId, Name = "content" });
db.Insert<Content>(new Content { Id = Guid.NewGuid(), Title = "New Title", CreatedAt = DateTime.Now, AccountId = accountId, ServiceId = serviceId });
db.Insert<Tag>(GetTags(accountId).ToArray());
}
}
catch (Exception ex)
{
Console.WriteLine(ex.StackTrace);
throw;
}
}
示例11: Init
private void Init(IDbConnectionFactory connectionFactory)
{
var orders = new List<Order>
{
new Order
{
Id = 1,
Location = "coffee shop",
Item = new OrderItem
{
Name = "Latte",
Quantity = 1,
Milk = "whole",
Size = "Large"
},
Cost = 3.95m,
Status = "Paid"
},
new Order
{
Id = 2,
Location = "drive through window",
Item = new OrderItem
{
Name = "Drip coffee",
Quantity = 3,
Milk = "no milk",
Size = "small"
},
Cost = 6.05m,
Status = "In Process"
},
new Order
{
Id = 3,
Location = "coffee shop",
Item = new OrderItem
{
Name = "Latte",
Quantity = 1,
Milk = "whole",
Size = "Large"
},
Cost = 3.95m,
Status = "ordered"
},
};
try
{
using (var dbConn = connectionFactory.OpenDbConnection())
using (var dbCmd = dbConn.CreateCommand())
{
dbCmd.CreateTable<Order>(false);
dbCmd.SaveAll(orders);
}
}
catch (Exception ex)
{
throw;
}
}
示例12: LoadSelected
public static List<Selected> LoadSelected(IDbConnectionFactory factory)
{
using(var connection = factory.OpenDbConnection())
{
var cmd = connection.CreateCommand();
var result = cmd.Select<Selected>("SELECT a.Id as AverageId, b.Id as AnotherId FROM test.averages a, test.anothers b where a.AnotherId = b.Id limit 50");
return result;
}
}
示例13: LoadAllTogether
public static List<AllTogether> LoadAllTogether(IDbConnectionFactory factory)
{
using(var connection = factory.OpenDbConnection())
{
var cmd = connection.CreateCommand();
var result = cmd.Select<AllTogether>("SELECT a.Id as AID, a.Name as AName, a.Hello as AHello, a.Year as AYear, " +
"a.Comments as AComments, a.Additional as AAdditional, a.AnotherId as AAnotherId, " +
"b.Id as BId, b.Name as BName, b.Hello as BHello, b.Year as BYear, " +
" b.Comments as BComments, b.Additional as BAdditional FROM test.averages a, test.anothers b where a.AnotherId = b.Id limit 50 ");
return result;
}
}
示例14: TodoRepository
public TodoRepository(IDbConnectionFactory dbFactory)
{
this._db = dbFactory.OpenDbConnection();
}