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


C# IDbConnection.TableExists方法代码示例

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


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

示例1: DropAndCreateTables

        private void DropAndCreateTables(IDbConnection db)
        {
            if (db.TableExists("ParamRelBO"))
                db.DropTable<ParamRelBO>();

            db.CreateTable<ParamTestBO>(true);
            db.CreateTable<ParamRelBO>(true);
        }
开发者ID:babcca,项目名称:ServiceStack.OrmLite,代码行数:8,代码来源:OracleParamTests.cs

示例2: DropTables

 private void DropTables(IDbConnection dbConnection)
 {
     if (dbConnection.TableExists("TWODUC")) dbConnection.DropTable<TypeWithOnDeleteAndUpdateCascade>();
     if (dbConnection.TableExists("TWODSN")) dbConnection.DropTable<TypeWithOnDeleteSetNull>();
     if (dbConnection.TableExists("TWODDF")) dbConnection.DropTable<TypeWithOnDeleteSetDefault>();
     if (dbConnection.TableExists("TWODNR")) dbConnection.DropTable<TypeWithOnDeleteRestrict>();
     if (dbConnection.TableExists("TWODNA")) dbConnection.DropTable<TypeWithOnDeleteNoAction>();
     if (dbConnection.TableExists("TWODC")) dbConnection.DropTable<TypeWithOnDeleteCascade>();
     if (dbConnection.TableExists("TWSKF")) dbConnection.DropTable<TypeWithSimpleForeignKey>();
     if (dbConnection.TableExists("TWONFKI")) dbConnection.DropTable<TypeWithNoForeignKeyInitially>();
 }
开发者ID:JackFong,项目名称:ServiceStack.OrmLite,代码行数:11,代码来源:ForeignKeyAttributeTests.cs

示例3: Execute

 public void Execute(IDbConnection db)
 {
     if (!db.TableExists(db.GetTableName<SiteSettings>()))
     {
         db.CreateTable<SiteSettings>();
     }
     else
     {
         // Append the analytics specific columns
         db.AddColumn<SiteSettings>(x => x.AnalyticsProfileId);
         db.AddColumn<SiteSettings>(x => x.AnalyticsToken);
     }
 }
开发者ID:Relix1990,项目名称:MvcKickstart,代码行数:13,代码来源:InitKickstartAnalytics.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

示例5: DropAndCreateTables

        private void DropAndCreateTables(IDbConnection db)
        {
            if (db.TableExists("ParamRelBO"))
                db.DropTable<ParamRelBo>();

            db.CreateTable<ParamTestBo>(true);
            db.CreateTable<ParamRelBo>(true);
            db.CreateTable<ParamByteBo>(true);
            db.CreateTable<ParamComment>(true);
            db.CreateTable<ParamOrder>(true);
            db.CreateTable<ParamLeft>(true);
            db.CreateTable<ParamUser>(true);
            db.CreateTable<ParamPassword>(true);
            db.CreateTable<ParamActive>(true);
            db.CreateTable<ParamDouble>(true);
            db.CreateTable<ParamFloat>(true);
            db.CreateTable<ParamDecimal>(true);
            db.CreateTable<ParamString>(true);
            db.CreateTable<ParamDate>(true);
            db.CreateTable<ParamDateTime>(true);
            db.CreateTable<ParamType>(true);
            db.CreateTable<ParamTimestamp>(true);
        }
开发者ID:JackFong,项目名称:ServiceStack.OrmLite,代码行数:23,代码来源:OracleParamTests.cs

示例6: AdjustFileForSpringDst

        private void AdjustFileForSpringDst(AgdFile agdFile, IDbConnection db, DaylightTime daylightTime)
        {
            //see if there's any epochs before DST
            int epochsBeforeSpringDst =
                db.Scalar<int>(
                    db.From<AgdTableTimestampAxis1>()
                        .Select(Sql.Count("*"))
                        .Where(q => q.TimestampTicks < daylightTime.Start.Ticks));
            bool dataBeforeSpringDst = epochsBeforeSpringDst > 0;

            int epochsAfterSpringDst =
                db.Scalar<int>(
                    db.From<AgdTableTimestampAxis1>()
                        .Select(Sql.Count("*"))
                        .Where(q => q.TimestampTicks > daylightTime.Start.Ticks));

            bool dataAfterSpringDst = epochsAfterSpringDst > 0;

            if (!dataBeforeSpringDst && dataAfterSpringDst)
            {
                //no need to do anything
                richTextBox1.AppendText(string.Format("{0}: NOT adjusting file for spring DST\r\n", agdFile));
                return;
            }

            richTextBox1.AppendText(string.Format("{0}: adjusting file for spring DST\r\n", agdFile));

            //adjust timestamps for data after DST by subtracting an hour
            string sql =
                string.Format(
                    "UPDATE data SET dataTimestamp = dataTimestamp + {0} WHERE dataTimestamp >= {1}",
                    daylightTime.Delta.Ticks, daylightTime.Start.Ticks);
            db.ExecuteSql(sql);

            //add the extra hour of data (October 25th 0200)
            var totalEpochsToInsert = daylightTime.Delta.TotalSeconds / agdFile.EpochLengthInSeconds;
            var ticksPerEpoch = TimeSpan.FromSeconds(agdFile.EpochLengthInSeconds).Ticks;
            for (int i = 0; i < totalEpochsToInsert; i++)
            {
                sql = string.Format("insert into data(dataTimestamp) values ({0});",
                    (daylightTime.Start.Ticks + (i * ticksPerEpoch)));
                db.ExecuteSql(sql);
            }

            var columnNames = db.GetColumnNames("data");
            foreach (var columnName in columnNames)
            {
                sql = string.Format("UPDATE data SET {0} = 0 WHERE {0} IS NULL", columnName);
                db.ExecuteSql(sql);
            }
            //adjust WTV
            if (db.TableExists("filters"))
            {
                sql =
                    string.Format(
                        "UPDATE filters SET filterStartTimestamp = filterStartTimestamp + {0} WHERE filterStartTimestamp >= {1}",
                        daylightTime.Delta.Ticks, daylightTime.Start.Ticks);
                db.ExecuteSql(sql);

                sql =
                    string.Format(
                        "UPDATE filters SET filterStopTimestamp = filterStopTimestamp + {0} WHERE filterStopTimestamp >= {1}",
                        daylightTime.Delta.Ticks, daylightTime.Start.Ticks);
                db.ExecuteSql(sql);
            }

            if (db.TableExists("wtvBouts"))
            {
                sql =
                    string.Format(
                        "UPDATE wtvBouts SET startTicks = startTicks + {0} WHERE startTicks >= {1}",
                        daylightTime.Delta.Ticks, daylightTime.Start.Ticks);
                db.ExecuteSql(sql);

                sql =
                    string.Format(
                        "UPDATE wtvBouts SET stopTicks = stopTicks + {0} WHERE stopTicks >= {1}",
                        daylightTime.Delta.Ticks, daylightTime.Start.Ticks);
                db.ExecuteSql(sql);
            }

            //adjust capsense
            if (db.TableExists("capsense"))
            {
                //adjust timestamps for data after DST by subtracting an hour
                sql = string.Format(
                        "UPDATE capsense SET timeStamp = timeStamp + {0} WHERE timeStamp >= {1}",
                        daylightTime.Delta.Ticks, daylightTime.Start.Ticks);
                db.ExecuteSql(sql);
            }
        }
开发者ID:DanielWJudge,项目名称:AgdAdjustDaylightSavings,代码行数:91,代码来源:MainWindow.cs

示例7: AdjustFileForFallDst

        private void AdjustFileForFallDst(AgdFile agdFile, IDbConnection db, DaylightTime daylightTime)
        {
            //see if there's any epochs before DST
            int epochsBeforeFallDst =
                db.Scalar<int>(
                    db.From<AgdTableTimestampAxis1>()
                        .Select(Sql.Count("*"))
                        .Where(q => q.TimestampTicks < daylightTime.End.Ticks));
            bool dataBeforeFallDst = epochsBeforeFallDst > 0;

            int epochsAfterFallDst =
                db.Scalar<int>(
                    db.From<AgdTableTimestampAxis1>()
                        .Select(Sql.Count("*"))
                        .Where(q => q.TimestampTicks > daylightTime.End.Ticks));
            bool dataAfterFallDst = epochsAfterFallDst > 0;

            if (dataBeforeFallDst && !dataAfterFallDst)
            {
                //there's only data before
                //no need to do anything
                richTextBox1.AppendText(string.Format("{0}: not adjusting file for fall DST\r\n", agdFile));
                return;
            }

            richTextBox1.AppendText(string.Format("{0}: adjusting file for fall DST\r\n", agdFile));

            //delete the extra hour of data (October 25th 0200)
            string sql = string.Format("DELETE FROM data WHERE dataTimestamp >= {0} AND dataTimeStamp < {1}",
                daylightTime.End.Ticks, daylightTime.End.Add(daylightTime.Delta).Ticks);
            db.ExecuteSql(sql);

            //adjust timestamps for data after DST by subtracting an hour
            sql =
                string.Format(
                    "UPDATE data SET dataTimestamp = dataTimestamp - {0} WHERE dataTimestamp >= {1}",
                    daylightTime.Delta.Ticks, daylightTime.End.Ticks);
            db.ExecuteSql(sql);

            //adjust WTV
            if (db.TableExists("filters"))
            {
                sql =
                    string.Format(
                        "UPDATE filters SET filterStartTimestamp = filterStartTimestamp - {0} WHERE filterStartTimestamp >= {1}",
                        daylightTime.Delta.Ticks, daylightTime.End.Ticks);
                db.ExecuteSql(sql);

                sql =
                    string.Format(
                        "UPDATE filters SET filterStopTimestamp = filterStopTimestamp - {0} WHERE filterStopTimestamp >= {1}",
                        daylightTime.Delta.Ticks, daylightTime.End.Ticks);
                db.ExecuteSql(sql);
            }

            if (db.TableExists("wtvBouts"))
            {
                sql =
                    string.Format(
                        "UPDATE wtvBouts SET startTicks = startTicks - {0} WHERE startTicks >= {1}",
                        daylightTime.Delta.Ticks, daylightTime.End.Ticks);
                db.ExecuteSql(sql);

                sql =
                    string.Format(
                        "UPDATE wtvBouts SET stopTicks = stopTicks - {0} WHERE stopTicks >= {1}",
                        daylightTime.Delta.Ticks, daylightTime.End.Ticks);
                db.ExecuteSql(sql);
            }

            //adjust capsense
            if (db.TableExists("capsense"))
            {
                //delete the extra hour of data (October 25th 0200)
                sql = string.Format("DELETE FROM capsense WHERE timeStamp  >= {0} AND timeStamp < {1}",
                    daylightTime.End.Ticks, daylightTime.End.Add(daylightTime.Delta).Ticks);
                db.ExecuteSql(sql);

                //adjust timestamps for data after DST by subtracting an hour
                sql =
                    string.Format(
                        "UPDATE capsense SET timeStamp = timeStamp - {0} WHERE timeStamp >= {1}",
                        daylightTime.Delta.Ticks, daylightTime.End.Ticks);
                db.ExecuteSql(sql);
            }
        }
开发者ID:DanielWJudge,项目名称:AgdAdjustDaylightSavings,代码行数:86,代码来源:MainWindow.cs


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