protected static IEnumerable <T> Get <T>(string sql) { var list = new List <T>(); var properties = typeof(T).GetProperties(); using (var conn = MicrosoftSQL.GetConnection()) { using (var comm = new MySqlCommand(GetCommandText(sql), conn)) { conn.Open(); using (var reader = comm.ExecuteReader()) { while (reader.Read()) { var element = Activator.CreateInstance <T>(); foreach (var f in properties) { var o = reader[f.Name]; if (o.GetType() != typeof(DBNull)) { f.SetValue(element, o, null); } o = null; } list.Add(element); } } conn.Close(); } } return(list); }
protected static int Delete(string sql, Dictionary <string, dynamic> fields) { using (MySqlConnection connection = MicrosoftSQL.GetConnection()) { connection.Open(); string cmdText = GetCommandText(sql); using (MySqlCommand command = new MySqlCommand(cmdText, connection)) { command.CommandType = System.Data.CommandType.Text; foreach (var item in fields) { command.Parameters.AddWithValue(item.Key, item.Value); } return(command.ExecuteNonQuery()); } } }