public int Delete <T>(IBussinessContext context, object value) where T : class, new() { int result = 0; using (MySqlCommand command = dbHelper.CreateCommand(context.Connection as MySqlConnection, dbHelper.Model2SQL <T>(Model2Db.Delete, value))) { result = command.ExecuteNonQuery(); } return(result); }
public long Add <T>(IBussinessContext context, T value) where T : class, new() { long result = 0; using (MySqlCommand command = dbHelper.CreateCommand(context.Connection as MySqlConnection, dbHelper.Model2SQL <T>(Model2Db.Add, value))) { result = command.ExecuteNonQuery(); result = command.LastInsertedId; } return(result); }
public List <T> GetAllByQuery <T>(IBussinessContext context, IQuery query) where T : class, new() { dbHelper.CheckKey <T>(); using (MySqlDataAdapter adapter = dbHelper.CreateAdapter(context.Connection as MySqlConnection, dbHelper.Model2SQL <T>(query))) { DataTable table = new DataTable(); adapter.Fill(table); IList <T> models = ModelConvertHelper <T> .ConvertToModel(table); return(models.ToList()); } }
public T Get <T>(IBussinessContext context, object id) where T : class, new() { dbHelper.CheckKey <T>(); using (MySqlDataAdapter adapter = dbHelper.CreateAdapter(context.Connection as MySqlConnection, dbHelper.Model2SQL <T>(Model2Db.Query, id))) { DataTable table = new DataTable(); adapter.Fill(table); IList <T> models = ModelConvertHelper <T> .ConvertToModel(table); if (models.Any()) { return(models.First()); } } return(default(T)); }
public DataContext(IBussinessContext context) { connection = context.Connection as MySqlConnection; this.connectionString = connection.ConnectionString; }