public static void SetConnectionKey(string key = "Connection") { string error_msg = ""; string SQL_ConnectionStr = GetConfig.Config("Cmd.config", System.Text.Encoding.UTF8, key, out error_msg); Connection.ConnectionString = SQL_ConnectionStr; }
public MySQLConnection() { //log init Console.WriteLine("ORM Init"); string error_msg = ""; string SQL_ConnectionStr = GetConfig.Config("Cmd.config", System.Text.Encoding.UTF8, "Connection", out error_msg); Connection.ConnectionString = SQL_ConnectionStr; }
/// <summary> /// 表映射到实体 /// </summary> /// <typeparam name="T">Model层</typeparam> /// <param name="TableName">表名</param> public static void Map <T>(string TableName) where T : class, new() { string Cmd = GetConfig.Config("/Config/Cmd.config", System.Text.Encoding.UTF8, "GetTableColumn"); MySqlDataReader reader = MySQLConnection.SqlDataReader(Cmd); Type t = (new T()).GetType(); PropertyInfo[] Propertys = t.GetProperties(); int index = 0; while (reader.Read()) { //SQLColumns.Add(reader[index].ToString()); bool IsExixt = false; int index_sealed = 1; foreach (PropertyInfo info in Propertys) { string Name = info.Name; if (Name == reader[index].ToString()) { //Entity.Add(Name); IsExixt = true; break; } if (IsExixt == false && Propertys.Count() == index_sealed) { //Entity.Clear(); Exception ex = new Exception(); ex.Source = "SQL Column And Property NoMate Error Column " + Name; } index_sealed++; // //string Value = info.GetValue(t).ToString(); } index++; } MapTables.Add(new MapTable() { EntityName = t.Name, TableName = TableName }); //string Cmd = GetConfig.Config("/Config/Cmd.config",System.Text.Encoding.UTF8,"GetTableColumn"); //MySqlDataReader reader = MySQLConnection.SqlDataReader(Cmd); }
/// <summary> /// 校验 表 与 实体 的 列是否一致 /// </summary> /// <typeparam name="T">Model层</typeparam> /// <param name="TableName">表名</param> public static void Map <T>(string TableName) where T : class, new() { string error_msg = ""; string Cmd = GetConfig.Config("Cmd.config", System.Text.Encoding.UTF8, "GetTableColumn", out error_msg); MySqlDataReader reader = MySQLConnection.SqlDataReader(string.Format(Cmd, TableName)); Type t = (new T()).GetType(); PropertyInfo[] Propertys = t.GetProperties(); int index = 0; while (reader.Read()) { bool IsExixt = false; int index_sealed = 1; foreach (PropertyInfo info in Propertys) { string Name = info.Name; object Index = reader.GetString("COLUMN_NAME"); if (Name == Index.ToString()) { IsExixt = true; break; } if (IsExixt == false && Propertys.Count() == index_sealed) { Exception ex = new Exception(); ex.Source = "SQL Column And Property NoMate Error Column " + Index; } index_sealed++; } index++; } reader.Close(); MapTables.Add(new MapTable() { EntityName = t.Name, TableName = TableName }); }