protected virtual IDbCommand CreateSQLInsertCommand(Persistence.ModelMaps.ModelMap modelMap, Dictionary <string, object> parameterValues) { //TODO:Tratar exceções Dictionary <string, object> values = new Dictionary <string, object>(); Dictionary <string, string> sequenceKeys = new Dictionary <string, string>(); foreach (string parameter in parameterValues.Keys) { Persistence.ModelMaps.ColumnMap columnMap = modelMap.GetColumnMap(parameter); if (columnMap != null) { if (!columnMap.IsAutoIncremented) { values.Add(columnMap.Column, parameterValues[parameter]); } else if (!string.IsNullOrEmpty(columnMap.SequenceName)) { sequenceKeys.Add(columnMap.Column, columnMap.SequenceName); } } } Persistence.Repository repository = GetDefaultRepository(modelMap); string sql = repository.DataBaseConnection.GetInsertSQL(modelMap.Table, values: values, sequenceKeys: sequenceKeys); IDbCommand command = repository.DataBaseConnection.GetCommand(sql, Persistence.DatabaseCommandType.NONQUERY); return(command); }
protected virtual IDbCommand CreateSQLSelectCommand(Persistence.ModelMaps.ModelMap modelMap, Dictionary <string, object> parameters) { //TODO:Tratar exceções Dictionary <string, object> filters = new Dictionary <string, object>(); if (parameters != null) { foreach (string parameter in parameters.Keys) { Persistence.ModelMaps.ColumnMap columnMap = modelMap.GetColumnMap(parameter); if (columnMap != null) { filters.Add(columnMap.Column, parameters[parameter]); } else { filters.Add(parameter, parameters[parameter]); } } } Persistence.Repository repository = GetDefaultRepository(modelMap); string sql = repository.DataBaseConnection.GetSelectSQL(modelMap.Table, filters: filters); IDbCommand command = repository.DataBaseConnection.GetCommand(sql, Persistence.DatabaseCommandType.SQL); return(command); }
public void UpdateProcedureReturnedFields <TModel>(TModel model, Dictionary <string, object> returnedValues, Persistence.ModelMaps.ProcedureMapInfo procedureMap) { Persistence.ModelMaps.ModelMap modelMap = Persistence.ModelMaps.ModelMap.GetModelMap(model.GetType()); foreach (string key in procedureMap.Parameters.Keys) { Persistence.ModelMaps.ProcedureParameter parameter = procedureMap.Parameters[key]; if (parameter.Direction != ParameterDirection.Input && returnedValues.ContainsKey(parameter.Name) && modelMap.GetColumnMap(key) != null) { typeof(TModel).GetProperty(key).SetValue(model, returnedValues[parameter.Name], null); } } }