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


C# IDbConnection.GetColumns方法代码示例

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


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

示例1: VerifyDataTableSchema

        void VerifyDataTableSchema(string dataTableName, IDbConnection connection)
        {
            //  [id] [uniqueidentifier] NOT NULL,
            //	[revision] [int] NOT NULL,
            //	[data] [varbinary](max) NOT NULL,
            var expectedDataTypes = new Dictionary<string, SqlDbType>(StringComparer.InvariantCultureIgnoreCase)
            {
                {"id", SqlDbType.UniqueIdentifier },
                {"revision", SqlDbType.Int },
                {"data", SqlDbType.VarBinary },
            };

            var columns = connection.GetColumns(dataTableName);

            foreach (var column in columns)
            {
                // we skip columns we don't know about - don't prevent people from adding their own columns
                if (!expectedDataTypes.ContainsKey(column.Name)) continue;

                var expectedDataType = expectedDataTypes[column.Name];

                if (column.Type == expectedDataType) continue;

                // special case: migrating from Rebus 0.99.59 to 0.99.60
                if (column.Name == "data" && column.Type == SqlDbType.NVarChar && expectedDataType == SqlDbType.VarBinary)
                {
                    throw new RebusApplicationException(@"Sorry, but the [data] column data type was changed from NVarChar(MAX) to VarBinary(MAX) in Rebus 0.99.60.

This was done because it turned out that SQL Server was EXTREMELY SLOW to load a saga's data when it was saved as NVarChar - you can expect a reduction in saga data loading time to about 1/10 of the previous time from Rebus version 0.99.60 and on.

Unfortunately, Rebus cannot help migrating any existing pieces of saga data :( so we suggest you wait for a good time when the saga data table is empty, and then you simply wipe the tables and let Rebus (re-)create them.");
                }

                throw new RebusApplicationException($"The column [{column.Name}] has the type {column.Type} and not the expected {expectedDataType} data type!");
            }
        }
开发者ID:RichieYang,项目名称:Rebus,代码行数:36,代码来源:SqlServerSagaStorage.cs


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