#endregion
#region GetPrimaryKey
public static string GetPrimaryKey(List
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 = \ } #>