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


C# IDbConnection.Save方法代码示例

本文整理汇总了C#中IDbConnection.Save方法的典型用法代码示例。如果您正苦于以下问题:C# IDbConnection.Save方法的具体用法?C# IDbConnection.Save怎么用?C# IDbConnection.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDbConnection的用法示例。


在下文中一共展示了IDbConnection.Save方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateArtistAndTrackTablesWithData

 public IDbConnection CreateArtistAndTrackTablesWithData(IDbConnection db)
 {
     db.DropAndCreateTable<Artist>();
     db.DropAndCreateTable<Track>();
     Artists.Each(x => db.Save(x, references: true));
     return db;
 }
开发者ID:CormacBrennan-AI,项目名称:ServiceStack.OrmLite,代码行数:7,代码来源:ArtistTrackTestBase.cs

示例2: RunMigrations

        /// <summary>
        /// Run all defined data migrations that have not been run yet
        /// </summary>
        /// <param name="db">current database connection</param>
        /// <returns>Count of migrations run</returns>
        public static int RunMigrations(IDbConnection db)
        {
            var migrationsRun = 0;
            var migrationTypes = GetMigrationTypes();

            var alreadyExecutedMigrations = db.Query<DataMigration>("select * from [{0}]".Fmt(db.GetTableName<DataMigration>())).ToList();

            if (!alreadyExecutedMigrations.Any(x => x.Name == typeof(InitializeDbMigration).Name))
            {
                // Create all data, run data init migration
                var schemaBuilder = new SchemaBuilder(db);
                schemaBuilder.GenerateSchema(false);

                var dataInitMigration = new InitializeDbMigration();
                dataInitMigration.Execute(db);

                // Populate all migrations as run
                var migrations = migrationTypes.Select(x => new DataMigration
                    {
                        Name = x.Name
                    });
                return db.BulkInsert(migrations);
            }

            var scriptedObjectsToRecreate = new List<Type>();
            foreach (var migration in migrationTypes.Where(t => !alreadyExecutedMigrations.Any(m => m.Name == t.Name)).Select(x => (IMigration)Activator.CreateInstance(x)).OrderBy(x => x.Order))
            {
                // Collect the scripted objects to recreate after migrations are run
                if (migration.ScriptedObjectsToRecreate != null && migration.ScriptedObjectsToRecreate.Any())
                {
                    foreach (var viewType in migration.ScriptedObjectsToRecreate.Where(viewType => !scriptedObjectsToRecreate.Any(v => v == viewType)))
                    {
                        scriptedObjectsToRecreate.Add(viewType);
                    }
                }

                migration.Execute(db);
                // add migration to database
                var migrationData = new DataMigration
                                        {
                                            CreatedOn = DateTime.UtcNow,
                                            Name = migration.GetType().Name
                                        };
                db.Save(migrationData);
                migrationsRun++;
            }
            if (scriptedObjectsToRecreate.Any())
            {
                foreach (var viewType in scriptedObjectsToRecreate)
                {
                    db.RecreateScriptedObject(viewType);
                }
            }

            return migrationsRun;
        }
开发者ID:Relix1990,项目名称:MvcKickstart,代码行数:61,代码来源:DataMigrator.cs

示例3: Execute

 public void Execute(IDbConnection db)
 {
     db.Save(new User
             {
                 Username = "admin",
                 Password = "admin".ToSHAHash(),
                 IsAdmin = true,
                 Email = "[email protected]",
             });
 }
开发者ID:Relix1990,项目名称:MvcKickstart,代码行数:10,代码来源:InitializeDbMigration.cs

示例4: RunMigrations

        /// <summary>
        /// Run all defined data migrations that have not been run yet
        /// </summary>
        /// <param name="db">current database connection</param>
        /// <returns>Count of migrations run</returns>
        public static int RunMigrations(IDbConnection db)
        {
            var migrationsRun = 0;
            var migrationTypes = GetMigrationTypes();

            if (!db.TableExists(db.GetTableName<DataMigration>()))
            {
                // Create all data, run data init migration
                var schemaBuilder = new SchemaBuilder(db);
                schemaBuilder.GenerateSchema(false);

                var dataInitMigration = new InitializeDbMigration();
                dataInitMigration.Execute(db);

                // Populate all migrations as run
                var migrations = migrationTypes.Select(x => new DataMigration
                    {
                        Name = x.Name
                    });
                return db.BulkInsert(migrations);
            }

            var alreadyExecutedMigrations = db.Query<DataMigration>("select * from [{0}]".Fmt(db.GetTableName<DataMigration>()));
            foreach (var migration in migrationTypes.Where(t => !alreadyExecutedMigrations.Any(m => m.Name == t.Name)).Select(x => (IMigration)Activator.CreateInstance(x)).OrderBy(x => x.Order))
            {
                migration.Execute(db);
                // add migration to database
                var migrationData = new DataMigration
                                        {
                                            CreatedOn = DateTime.UtcNow,
                                            Name = migration.GetType().Name
                                        };
                db.Save(migrationData);
                migrationsRun++;
            }

            return migrationsRun;
        }
开发者ID:pleepleus88,项目名称:MvcKickstart,代码行数:43,代码来源:DataMigrator.cs


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