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


C# IDbConnectionFactory.Open方法代码示例

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

示例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);
                }
            }
        }
开发者ID:WildGenie,项目名称:Bastet-Legacy,代码行数:51,代码来源:Database.cs

示例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"
                });
            }
        }
开发者ID:sanjayuttam,项目名称:Sanjay.Io.UnitTestingRepositories,代码行数:17,代码来源:CustomerRepositoryTest.cs

示例4: MetroiLinksService

 public MetroiLinksService(IDbConnectionFactory dbConnectionFactory)
 {
     Repository = new OrmLiteRepository<MetroiLinks>(dbConnectionFactory.Open());
 }
开发者ID:KyleGobel,项目名称:ServiceStackJetNettApi,代码行数:4,代码来源:MetroiLinksService.cs

示例5: ClientsService

 public ClientsService(IDbConnectionFactory dbConnectionFactory)
 {
     Repository = new OrmLiteRepository<Client>(dbConnectionFactory.Open());
 }
开发者ID:KyleGobel,项目名称:ServiceStackJetNettApi,代码行数:4,代码来源:ClientService.cs

示例6: FolderService

 public FolderService(IDbConnectionFactory dbConnectionFactory)
 {
     Repository = new OrmLiteRepository<Folder>(dbConnectionFactory.Open());
 }
开发者ID:KyleGobel,项目名称:ServiceStackJetNettApi,代码行数:4,代码来源:FolderService.cs


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