本文整理汇总了C#中Schema.FindTypeDefinition方法的典型用法代码示例。如果您正苦于以下问题:C# Schema.FindTypeDefinition方法的具体用法?C# Schema.FindTypeDefinition怎么用?C# Schema.FindTypeDefinition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Schema
的用法示例。
在下文中一共展示了Schema.FindTypeDefinition方法的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" );
//.........这里部分代码省略.........