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


C# Schema.FindSchemaObject方法代码示例

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


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

示例1: Test_Basic

        public void Test_Basic()
        {
            using (var sqlConnection = new SqlConnection (@"Data Source=.\SQLEXPRESS;Initial Catalog=tempdb;Integrated Security=True"))
            {
                sqlConnection.Open ();

                try
                {
                    ExecuteScript(sqlConnection, SetupText);

                    var schema = new Schema (sqlConnection);

                    using (var cmd = sqlConnection.CreateCommand ())
                    {
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = GetTypesText;

                        var typeCount = 0;
                        using (var reader = cmd.ExecuteReader ())
                        {
                            while (reader.Read())
                            {
                                ++typeCount;

                                var fullName = reader.Get("schema", "") + "." + reader.Get("name", "");

                                var typeDefinition = schema.FindTypeDefinition (fullName);

                                if (TestFor.Equality(true, typeDefinition != null, "{0} must exist".FormatWith(fullName)))
                                {
                                    TestFor.Equality(reader.Get("name"          , "")       , typeDefinition.Name           , "Name must match"         );
                                    TestFor.Equality(reader.Get("system_type_id", (byte)0)  , typeDefinition.SystemTypeId   , "SystemTypeId must match" );
                                    TestFor.Equality(reader.Get("user_type_id"  , 0)        , typeDefinition.UserTypeId     , "UserTypeId must match"   );
                                    TestFor.Equality(reader.Get("max_length"    , 0)        , typeDefinition.MaxLength      , "MaxLength must match"    );
                                    TestFor.Equality(reader.Get("precision"     , 0)        , typeDefinition.Precision      , "Precision must match"    );
                                    TestFor.Equality(reader.Get("scale"         , 0)        , typeDefinition.Scale          , "Scale must match"        );
                                    TestFor.Equality(reader.Get("is_nullable"   , false)    , typeDefinition.IsNullable     , "IsNullable must match"   );

                                }

                            }
                        }

                        TestFor.Equality (typeCount, schema.TypeDefinitions.Count (), "Schema type count must match");
                    }

                    using (var cmd = sqlConnection.CreateCommand ())
                    {
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = GetObjectsText;

                        var objectCount = 0;
                        using (var reader = cmd.ExecuteReader ())
                        {
                            while (reader.Read())
                            {
                                ++objectCount;
                                var fullName = reader.Get("schema", "") + "." + reader.Get("name", "");

                                var schemaObject = schema.FindSchemaObject (fullName);

                                if (TestFor.Equality(true, schemaObject != null, "{0} must exist".FormatWith(fullName)))
                                {
                                    TestFor.Equality(reader.Get("object_id"     , 0)                , schemaObject.Id                   , "Id must match"           );
                                    TestFor.Equality(reader.Get("schema"        , "")               , schemaObject.Schema               , "Schema must match"       );
                                    TestFor.Equality(reader.Get("name"          , "")               , schemaObject.Name                 , "Name must match"         );
                                    TestFor.Equality(reader.Get("type"          , "").Trim ()       , TypeToString (schemaObject.Type)  , "Type must match"         );
                                    TestFor.Equality(reader.Get("create_date"   , DateTime.MinValue), schemaObject.CreateDate           , "CreateDate must match"   );
                                    TestFor.Equality(reader.Get("modify_date"   , DateTime.MinValue), schemaObject.ModifyDate           , "ModifyDate must match"   );

                                }
                            }
                        }
                        TestFor.Equality (objectCount, schema.SchemaObjects.Count (), "Object count must match");
                    }

                    using (var cmd = sqlConnection.CreateCommand ())
                    {
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = GetColumnsText;

                        var columnCount = 0;
                        using (var reader = cmd.ExecuteReader ())
                        {
                            while (reader.Read())
                            {
                                ++columnCount;
                                var fullName = reader.Get("object_schema", "") + "." + reader.Get("object_name", "");
                                var columnId = reader.Get("column_id", 0);

                                var schemaObject = schema.FindSchemaObject (fullName);

                                if (TestFor.Equality(true, schemaObject != null, "{0} must exist".FormatWith(fullName)))
                                {
                                    var columnSubObject = schemaObject.Columns.FirstOrDefault(c => c.Id == columnId);

                                    if (TestFor.Equality(true, columnSubObject != null, "Column {0} must exist".FormatWith(columnId)))
                                    {
                                        TestFor.Equality(columnId                               , columnSubObject.Id                , "Id must match"           );
                                        TestFor.Equality(reader.Get("column_name"   , "")       , columnSubObject.Name              , "Name must match"         );
//.........这里部分代码省略.........
开发者ID:mrange,项目名称:T4Include,代码行数:101,代码来源:TestsFor_Schema.cs


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