Exemple #1
0
        protected virtual IList <string> GetUpdateOfColumnNameList(IUpdateOfModel <T> updateOf, IEnumerable <ColumnInfo> tableColumns)
        {
            var updateOfList = new List <string>();

            if (updateOf == null || updateOf.Count() <= 0)
            {
                return(updateOfList);
            }

            foreach (var propertyInfo in updateOf.GetPropertiesInfos())
            {
                var existingMap = _mapper?.GetMapping(propertyInfo);
                if (existingMap != null)
                {
                    updateOfList.Add(existingMap);
                    continue;
                }

                var attribute = propertyInfo.GetCustomAttribute(typeof(ColumnAttribute));
                if (attribute != null)
                {
                    var dbColumnName = ((ColumnAttribute)attribute).Name;
                    updateOfList.Add(dbColumnName);
                }
                else
                {
                    var dbColumnName = GetColumnNameFromModelProperty(tableColumns, propertyInfo.Name);
                    updateOfList.Add(dbColumnName);
                }
            }

            return(updateOfList);
        }
Exemple #2
0
        protected TableDependency(
            string connectionString,
            string schemaName = null,
            string tableName  = null,
            IModelToTableMapper <T> mapper  = null,
            IUpdateOfModel <T> updateOf     = null,
            ITableDependencyFilter filter   = null,
            DmlTriggerType dmlTriggerType   = DmlTriggerType.All,
            bool executeUserPermissionCheck = true)
        {
            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(schemaName);
            _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;
        }
Exemple #3
0
        protected virtual void CheckUpdateOfCongruenceWithTriggerType(IUpdateOfModel <T> updateOf, DmlTriggerType dmlTriggerType)
        {
            if (updateOf == null || updateOf.Count() == 0)
            {
                return;
            }

            if (!dmlTriggerType.HasFlag(DmlTriggerType.Update) && !dmlTriggerType.HasFlag(DmlTriggerType.All))
            {
                if (updateOf.Count() > 0)
                {
                    throw new DmlTriggerTypeException("updateOf parameter can be specified only if DmlTriggerType parameter contains DmlTriggerType.Update too, not for DmlTriggerType.Delete or DmlTriggerType.Insert only.");
                }
            }
        }
 public SqlTableDependencyTest(
     string connectionString,
     string tableName  = null,
     string schemaName = null,
     IModelToTableMapper <T> mapper  = null,
     IUpdateOfModel <T> updateOf     = null,
     ITableDependencyFilter filter   = null,
     DmlTriggerType notifyOn         = DmlTriggerType.All,
     bool executeUserPermissionCheck = true,
     bool includeOldValues           = false,
     bool throwExceptionBeforeWaitForNotifications     = false,
     bool throwExceptionInWaitForNotificationsPoint1   = false,
     bool throwExceptionInWaitForNotificationsPoint2   = false,
     bool throwExceptionInWaitForNotificationsPoint3   = false,
     bool throwExceptionCreateSqlServerDatabaseObjects = false) : base(connectionString, tableName, schemaName, mapper, updateOf, filter, notifyOn, executeUserPermissionCheck, includeOldValues)
 {
     _throwExceptionBeforeWaitForNotifications     = throwExceptionBeforeWaitForNotifications;
     _throwExceptionInWaitForNotificationsPoint1   = throwExceptionInWaitForNotificationsPoint1;
     _throwExceptionInWaitForNotificationsPoint2   = throwExceptionInWaitForNotificationsPoint2;
     _throwExceptionInWaitForNotificationsPoint3   = throwExceptionInWaitForNotificationsPoint3;
     _throwExceptionCreateSqlServerDatabaseObjects = throwExceptionCreateSqlServerDatabaseObjects;
 }
 public SqlTableDependencyWithReconnection(string connectionString, string tableName = null, string schemaName = null, IModelToTableMapper <TEntity> mapper = null, IUpdateOfModel <TEntity> updateOf = null, ITableDependencyFilter filter = null, DmlTriggerType notifyOn = DmlTriggerType.All, bool executeUserPermissionCheck = true, bool includeOldValues = false)
     : base(connectionString, tableName, schemaName, mapper, updateOf, filter, notifyOn, executeUserPermissionCheck, includeOldValues)
 {
 }