public SqlTableDependencyFilter(Expression filter, IModelToTableMapper <T> modelMapperDictionary = null) { _filter = filter; _modelMapperDictionary = modelMapperDictionary != null && modelMapperDictionary.Count() > 0 ? modelMapperDictionary.GetMappings().ToDictionary(kvp => kvp.Key.Name, kvp => kvp.Value) : this.CreateModelToTableMapperHelper()?.GetMappings().ToDictionary(kvp => kvp.Key.Name, kvp => kvp.Value); }
public SqlTableDependencyFilter(Expression filter, IModelToTableMapper <T> modelMapperDictionary = null) { _filter = filter; _modelMapperDictionary = modelMapperDictionary != null && modelMapperDictionary.Count() > 0 ? modelMapperDictionary.GetMappings().ToDictionary(kvp => kvp.Key.Name, kvp => kvp.Value) : ModelToTableMapperHelper <T> .GetModelMapperFromColumnDataAnnotation()?.GetMappings().ToDictionary(kvp => kvp.Key.Name, kvp => kvp.Value); }
protected TableDependency( string connectionString, string tableName = null, IModelToTableMapper <T> mapper = null, IUpdateOfModel <T> updateOf = null, ITableDependencyFilter filter = null, DmlTriggerType dmlTriggerType = DmlTriggerType.All, bool executeUserPermissionCheck = false) { if (mapper?.Count() == 0) { throw new UpdateOfException("mapper parameter is empty."); } if (updateOf?.Count() == 0) { throw new UpdateOfException("updateOf parameter is empty."); } this.CheckIfConnectionStringIsValid(connectionString); this.CheckIfParameterlessConstructorExistsForModel(); if (!executeUserPermissionCheck) { this.CheckIfUserHasPermissions(connectionString); } _connectionString = connectionString; _tableName = this.GetTableName(tableName); _schemaName = this.GetSchemaName(tableName); _server = this.GetServerName(connectionString); _database = this.GetDataBaseName(connectionString); this.CheckIfTableExists(connectionString); this.CheckRdbmsDependentImplementation(connectionString); var tableColumnList = this.GetTableColumnsList(connectionString); if (!tableColumnList.Any()) { throw new TableWithNoColumnsException(tableName); } _mapper = mapper ?? this.GetModelMapperFromColumnDataAnnotation(); this.CheckMapperValidity(tableColumnList); this.CheckUpdateOfCongruenceWithTriggerType(updateOf, dmlTriggerType); _updateOf = this.GetUpdateOfColumnNameList(updateOf, tableColumnList); _userInterestedColumns = this.GetUserInterestedColumns(tableColumnList); if (!_userInterestedColumns.Any()) { throw new NoMatchBetweenModelAndTableColumns(); } this.CheckIfUserInterestedColumnsCanBeManaged(_userInterestedColumns); _dataBaseObjectsNamingConvention = this.GetBaseObjectsNamingConvention(); _dmlTriggerType = dmlTriggerType; _filter = filter; }
protected virtual void CheckMapperValidity(IEnumerable <ColumnInfo> tableColumnsList) { if (_mapper == null || _mapper.Count() < 1) { return; } var dbColumnNames = tableColumnsList.Select(t => t.Name.ToLowerInvariant()).ToList(); if (_mapper.GetMappings().Select(t => t.Value).Any(mappingColumnName => !dbColumnNames.Contains(mappingColumnName.ToLowerInvariant()))) { throw new ModelToTableMapperException("I cannot find any correspondence between defined ModelToTableMapper properties and database Table columns."); } }