public void Persist(PacketData entity) { // INSERT Dictionary <string, object> commands = new Dictionary <string, object>(); string query = "INSERT INTO " + entity.Definition.Name + " VALUES("; int count = 0; for (int i = 0; i < entity.Definition.Items.Length; i++) { query += "@" + count.ToString(); commands.Add("@" + count.ToString(), entity.Get(entity.Definition.Items[i].Name)); if ((i + 1) < (entity.Definition.Items.Length)) { query += ", "; } count++; } query += ")"; customRepository.ExecuteQuery(query, commands); }
public void Merge(PacketData entity, string[] keys) { // UPDATE Dictionary <string, string> commandNames = new Dictionary <string, string>(); Dictionary <string, object> commands = new Dictionary <string, object>(); string query = "UPDATE " + entity.Definition.Name + " SET "; int count = 0; for (int i = 0; i < entity.Definition.Items.Length; i++) { query += entity.Definition.Items[i].Name + "=" + "@" + count.ToString(); commands.Add("@" + count.ToString(), entity.Get(entity.Definition.Items[i].Name)); commandNames.Add(entity.Definition.Items[i].Name, "@" + count.ToString()); if ((i + 1) < (entity.Definition.Items.Length)) { query += ", "; } count++; } query += " WHERE "; for (int i = 0; i < keys.Length; i++) { string key = keys[i]; query += key + "=" + commandNames[key]; if ((i + 1) < (keys.Length)) { query += " AND "; } } customRepository.ExecuteQuery(query, commands); }
public void Remove(PacketData entity, string[] keys) { // DELETE Dictionary <string, object> commands = new Dictionary <string, object>(); string query = "DELETE FROM " + entity.Definition.Name + " WHERE "; int count = 0; for (int i = 0; i < keys.Length; i++) { query += keys[i] + "=" + "@" + count.ToString(); commands.Add("@" + count.ToString(), entity.Get(keys[i])); if ((i + 1) < (keys.Length)) { query += " AND "; } count++; } customRepository.ExecuteQuery(query, commands); }