当前位置: 首页>>代码示例>>C#>>正文


C# IDbConnectionFactory.OpenDbConnection方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:Dynalon,项目名称:Rainy,代码行数:16,代码来源:DbTestsBase.cs

示例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;
     }
 }
开发者ID:seba-i,项目名称:Template,代码行数:16,代码来源:ConfigureDatabase.cs

示例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;
     }
 }
开发者ID:firstsee,项目名称:ServiceStack,代码行数:16,代码来源:ConfigureDatabase.cs

示例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;
     }
 }
开发者ID:Qasemt,项目名称:ServiceStack.Examples,代码行数:17,代码来源:ConfigureDatabase.cs

示例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 ();
        }
开发者ID:Dynalon,项目名称:Rainy,代码行数:17,代码来源:DbStorage.cs

示例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 ();
        }
开发者ID:Dynalon,项目名称:tomboy-library,代码行数:19,代码来源:DatabaseStorage.cs

示例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> ();
                }
            }
        }
开发者ID:rashoodkhan,项目名称:Rainy,代码行数:41,代码来源:DatabaseBackend.cs

示例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);
            }
        }
开发者ID:wickdninja,项目名称:StackApis,代码行数:59,代码来源:UnitTests.cs

示例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;
            }
        }
开发者ID:qualtrak,项目名称:servicestack-test,代码行数:29,代码来源:AppHost.cs

示例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;
            }
        }
开发者ID:louissalin,项目名称:RestBucks,代码行数:62,代码来源:IntegrationTestBase.cs

示例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;
     }
 }
开发者ID:sergey-korol,项目名称:uniform,代码行数:9,代码来源:Program.cs

示例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;
            }
        }
开发者ID:sergey-korol,项目名称:uniform,代码行数:13,代码来源:Program.cs

示例14: TodoRepository

 public TodoRepository(IDbConnectionFactory dbFactory)
 {
     this._db = dbFactory.OpenDbConnection();
 }
开发者ID:qualtrak,项目名称:servicestack-test,代码行数:4,代码来源:TodoRepository.cs


注:本文中的IDbConnectionFactory.OpenDbConnection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。