日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

.net mysql 类库_(精华)2020年6月27日 C#类库 MySqlHelper(Ado.net数据库封装)

發布時間:2024/9/27 数据库 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 .net mysql 类库_(精华)2020年6月27日 C#类库 MySqlHelper(Ado.net数据库封装) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

using EFCore.Sharding;

using MySql.Data.MySqlClient;

using System;

using System.Collections.Generic;

using System.Data.Common;

namespace Core.Util

{

///

/// MySql數據庫操作幫助類

///

public class MySqlHelper : DbHelper

{

#region 構造函數

///

/// 構造函數

///

/// 完整連接字符串

public MySqlHelper(string conString)

: base(DatabaseType.MySql, conString)

{

}

#endregion

#region 私有成員

protected override Dictionary DbTypeDic { get; } = new Dictionary

{

{ "boolean",typeof(bool)},

{ "bit(1)",typeof(bool)},

{ "tinyint unsigned",typeof(bool)},

{ "binary",typeof(byte[])},

{ "varbinary",typeof(byte[])},

{ "blob",typeof(byte[])},

{ "longblob",typeof(byte[])},

{ "datetime",typeof(DateTime)},

{ "double",typeof(double)},

{ "char(36)",typeof(Guid)},

{ "smallint",typeof(Int16)},

{ "int",typeof(Int32)},

{ "bigint",typeof(Int64)},

{ "tinyint",typeof(bool)},

{ "float",typeof(float)},

{ "decimal",typeof(decimal)},

{ "char",typeof(string)},

{ "varchar",typeof(string)},

{ "text",typeof(string)},

{ "longtext",typeof(string)},

{ "time",typeof(TimeSpan)}

};

#endregion

#region 外部接口

///

/// 獲取數據庫中的所有表

///

/// 模式(架構)

///

public override List GetDbAllTables(string schemaName = null)

{

DbProviderFactory dbProviderFactory = DbProviderFactoryHelper.GetDbProviderFactory(_dbType);

string dbName = string.Empty;

using (DbConnection conn = dbProviderFactory.CreateConnection())

{

conn.ConnectionString = _conString;

dbName = conn.Database;

}

string sql = @"SELECT TABLE_NAME as TableName,table_comment as Description

FROM INFORMATION_SCHEMA.TABLES

WHERE TABLE_SCHEMA = @dbName";

return GetListBySql(sql, new List { new MySqlParameter("@dbName", dbName) });

}

///

/// 通過連接字符串和表名獲取數據庫表的信息

///

/// 表名

///

public override List GetDbTableInfo(string tableName)

{

DbProviderFactory dbProviderFactory = DbProviderFactoryHelper.GetDbProviderFactory(_dbType);

string dbName = string.Empty;

using (DbConnection conn = dbProviderFactory.CreateConnection())

{

conn.ConnectionString = _conString;

dbName = conn.Database;

}

string sql = @"select DISTINCT

a.COLUMN_NAME as Name,

a.DATA_TYPE as Type,

(a.COLUMN_KEY = 'PRI') as IsKey,

(a.IS_NULLABLE = 'YES') as IsNullable,

a.COLUMN_COMMENT as Description,

a.ORDINAL_POSITION

from information_schema.columns a

where table_name=@tableName and table_schema=@dbName

ORDER BY a.ORDINAL_POSITION";

return GetListBySql(sql, new List { new MySqlParameter("@tableName", tableName), new MySqlParameter("@dbName", dbName) });

}

///

/// 生成實體文件

///

/// 表字段信息

/// 表名

/// 表描述信息

/// 文件路徑(包含文件名)

/// 實體命名空間

/// 架構(模式)名

public override void SaveEntityToFile(List infos, string tableName, string tableDescription, string filePath, string nameSpace, string schemaName = null)

{

base.SaveEntityToFile(infos, tableName, tableDescription, filePath, nameSpace, schemaName);

}

#endregion

}

}

總結

以上是生活随笔為你收集整理的.net mysql 类库_(精华)2020年6月27日 C#类库 MySqlHelper(Ado.net数据库封装)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。