/*public List<T> Read<T>() * { * * var myReturnList = new List<T>(); * * using (MySqlConnection connection = new MySqlConnection(ConnectionString)) * { * using (LocalDbContext contextDB = new LocalDbContext(connection, false)) * { * Type type = typeof(T); * * try * { * // read data from table T1 * if (type == typeof(T1)) * { * foreach (var item in contextDB.T1_Table) * { * myReturnList.Add((T)Convert.ChangeType(item, typeof(T))); * } * } * * // read data from table T2 * if (type == typeof(T2)) * { * foreach (var item in contextDB.T2_Table) * { * myReturnList.Add((T)Convert.ChangeType(item, typeof(T))); * } * } * } * catch (Exception) * { * return null; * } * } * } * return myReturnList; * }*/ // insert data into table T1 public static bool Insert(T1 entity) { try { // reset context contextDB = null; ContextDB.T1_Table.Add(entity); ContextDB.SaveChanges(); } catch (Exception e) { return(false); } return(true); }
// delete data in table T1 public static bool Delete(T1 entity) { try { // reset context contextDB = null; ContextDB.T1_Table.Attach(entity); ContextDB.T1_Table.Remove(entity); ContextDB.SaveChanges(); } catch (Exception e) { return(false); } return(true); }