NFine框架的T4模板(3)

2019-04-23 18:57

#endregion

#region GetPrimaryKey

public static string GetPrimaryKey(List dbColumns) {

string primaryKey = string.Empty;

if (dbColumns!=null&&dbColumns.Count>0) {

foreach (var item in dbColumns) {

if (item.IsPrimaryKey==true) {

primaryKey = item.ColumnName; } } }

return primaryKey; }

#endregion }

#region DbTable ///

/// 表结构 ///

public sealed class DbTable {

///

/// 表名称 ///

public string TableName { get; set; } ///

/// 表的架构 ///

public string SchemaName { get; set; } ///

/// 表的记录数 ///

public int Rows { get; set; }

///

/// 是否含有主键 ///

public bool HasPrimaryKey { get; set; }

}

#endregion

#region DbColumn ///

/// 表字段结构 ///

public sealed class DbColumn {

///

/// 字段ID ///

public int ColumnID { get; set; }

///

/// 是否主键 ///

public bool IsPrimaryKey { get; set; }

///

/// 字段名称 ///

public string ColumnName { get; set; }

///

/// 字段类型 ///

public string ColumnType { get; set; }

///

/// 数据库类型对应的C#类型 ///

public string CSharpType {

get {

return SqlServerDbTypeMap.MapCsharpType(ColumnType); } }

///

///

///

public Type CommonType

{

get {

return SqlServerDbTypeMap.MapCommonType(ColumnType); } }

///

/// 字节长度 ///

public int ByteLength { get; set; }

///

/// 字符长度 ///

public int CharLength { get; set; }

///

/// 小数位 ///

public int Scale { get; set; }

///

/// 是否自增列 ///

public bool IsIdentity { get; set; }

///

/// 是否允许空 ///

public bool IsNullable { get; set; }

///

/// 描述

///

public string Remark { get; set; } }

#endregion

#region SqlServerDbTypeMap

public class SqlServerDbTypeMap {

public static string MapCsharpType(string dbtype)

{

if (string.IsNullOrEmpty(dbtype)) return dbtype; dbtype = dbtype.ToLower(); string csharpType = \ switch (dbtype) {

case \ case \ case \ case \ case \ case \ case \

case \ case \ case \ case \ case \

case \ case \ case \

case \ case \ case \

case \ case \

case \ case \ case \ case \

case \ case \ case \

case \ case \ case \ case \ default: csharpType = \ }

return csharpType; }

public static Type MapCommonType(string dbtype) {

if (string.IsNullOrEmpty(dbtype)) return Type.Missing.GetType(); dbtype = dbtype.ToLower();

Type commonType = typeof(object); switch (dbtype) {

case \ case \ case \ case \ case \ case \ case \

case \ case \ case \ case \ case \

case \ case \ case \

case \ case \ case \

case \ case \

case \ case \ case \

case \ case \ case \ case \

case \ case \ case \ case \ default: commonType = typeof(object); break; }

return commonType; } }

#endregion #>

<#+

public class config {

public static readonly string ConnectionString = \Source=(local);Initial Catalog=NFineBase;User ID=sa;Password=hjf19870810;\

public static readonly string DbDatabase = \ public static readonly string TableName = \ } #>


NFine框架的T4模板(3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:沪科版压强第一章节压力压强练习题及答案 - 图文

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: