/// <summary> /// SQL Statement Build Provider Constructor /// </summary> /// <param name="selectStatementBuilder">Select Statement Builder</param> /// <param name="insertStatementBuilder">Insert Statement Builder</param> /// <param name="updateStatementBuilder">Update Statement Builder</param> /// <param name="conditionBuilder">Condition Builder</param> public SqlStatementBuildProvider(ISelectStatementBuilder selectStatementBuilder, IInsertStatementBuilder insertStatementBuilder, IUpdateStatementBuilder updateStatementBuilder, IConditionBuilder conditionBuilder) { _selectStatementBuilder = selectStatementBuilder ?? throw new ArgumentNullException(nameof(selectStatementBuilder)); _insertStatementBuilder = insertStatementBuilder ?? throw new ArgumentNullException(nameof(insertStatementBuilder)); _updateStatementBuilder = updateStatementBuilder ?? throw new ArgumentNullException(nameof(updateStatementBuilder)); _conditionBuilder = conditionBuilder ?? throw new ArgumentNullException(nameof(conditionBuilder)); }
/// <inheritdoc /> public string BuildUpdateStatement <T>(T dataModel) where T : class { if (dataModel == null) { throw new ArgumentNullException(nameof(dataModel)); } var dataModelTable = dataModel.GetThuriaDataModelTableName(); var dataModelColumns = dataModel.GetThuriaDataModelColumns(DbContextAction.Update); var whereCondition = GetWhereConditionsForDataModel(DbContextAction.Update, dataModel); string sqlStatement; lock (_updateBuilderLock) { _updateStatementBuilder.Clear(); _updateStatementBuilder = _updateStatementBuilder.WithTable(dataModelTable); foreach (var currentColumn in dataModelColumns) { var propertyValue = dataModel.GetPropertyValue(currentColumn.PropertyName); if (propertyValue == null || propertyValue.Equals(propertyValue.GetType().GetDefaultData())) { continue; } _updateStatementBuilder.WithColumn(currentColumn.ColumnName, propertyValue); } if (!string.IsNullOrWhiteSpace(whereCondition)) { _updateStatementBuilder.WithWhereCondition(whereCondition); } sqlStatement = _updateStatementBuilder.Build(); } return(sqlStatement); }
public MoranbernateUpdateBuilder(IUpdateStatementBuilder <T> builder) { _builder = builder; }