本文整理汇总了C#中IConnectionInfo.GetTypeName方法的典型用法代码示例。如果您正苦于以下问题:C# IConnectionInfo.GetTypeName方法的具体用法?C# IConnectionInfo.GetTypeName怎么用?C# IConnectionInfo.GetTypeName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IConnectionInfo
的用法示例。
在下文中一共展示了IConnectionInfo.GetTypeName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PrepareTableEntity
private static TableData PrepareTableEntity(IConnectionInfo cxInfo, ModuleBuilder moduleBuilder, IDbConnection dbConnection, string nameSpace, string databaseName, string tableName, ExplorerItem tableExplorerItem)
{
// get primary key columns
var primaryKeyColumns = dbConnection.GetPrimaryKeyColumns(tableName);
var typeName = $"{nameSpace}.{cxInfo.GetTypeName(tableName)}";
// ToDo make sure tablename can be used
var typeBuilder = moduleBuilder.DefineType(typeName, TypeAttributes.Public, typeof(Entity));
// add the table attribute to the class
typeBuilder.AddTableAttribute(tableName);
var query = SqlHelper.LoadSql("QueryColumns.sql");
var propertyAndFieldNames = new HashSet<string>();
var columns = dbConnection.Query(query, new { DatabaseName = databaseName, TableName = tableName });
foreach (var column in columns)
{
var columnName = cxInfo.GetColumnName((string)column.ColumnName);
var isPrimaryKeyColumn = primaryKeyColumns.Contains((string)column.ColumnName); // always use the unmodified column name
var columnDefault = (string)column.ColumnDefault;
// always make primary key columns nullable (otherwise auto increment can't be used with an insert)
var fieldType = (Type)SqlHelper.MapDbTypeToType(column.DataType, column.UdtName, "YES".Equals(column.Nullable, StringComparison.InvariantCultureIgnoreCase), cxInfo.UseAdvancedTypes());
string text;
if (fieldType != null)
{
// ToDo make sure name can be used
var fieldBuilder = typeBuilder.DefineField(columnName, fieldType, FieldAttributes.Public);
fieldBuilder.AddColumnAttribute((string)column.ColumnName); // always use the unmodified column name
if (isPrimaryKeyColumn)
{
// check if the column is an identity column
if (!string.IsNullOrEmpty(columnDefault) && columnDefault.ToLower().StartsWith("nextval"))
{
fieldBuilder.AddIdentityAttribute();
}
fieldBuilder.AddPrimaryKeyAttribute();
}
text = $"{columnName} ({fieldType.GetTypeName()})";
propertyAndFieldNames.Add(columnName);
}
else
{
// field type is not mapped
text = $"{columnName} (unsupported - {column.DataType})";
}
var explorerItem = new ExplorerItem(text, ExplorerItemKind.Property, ExplorerIcon.Column)
{
SqlTypeDeclaration = column.DataType,
DragText = columnName
};
tableExplorerItem.Children.Add(explorerItem);
}
return new TableData(tableName, tableExplorerItem, typeBuilder, propertyAndFieldNames);
}