protected virtual IModelToTableMapper <T> GetModelMapperFromColumnDataAnnotation() { var modelPropertyInfosWithColumnAttribute = typeof(T) .GetProperties(BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public) .Where(x => CustomAttributeExtensions.IsDefined(x, typeof(ColumnAttribute), false)) .ToArray(); if (!modelPropertyInfosWithColumnAttribute.Any()) { return(null); } var mapper = new ModelToTableMapper <T>(); foreach (var propertyInfo in modelPropertyInfosWithColumnAttribute) { var attribute = propertyInfo.GetCustomAttribute(typeof(ColumnAttribute)); var dbColumnName = ((ColumnAttribute)attribute)?.Name; if (dbColumnName != null && mapper.GetMapping(dbColumnName) == null) { mapper.AddMapping(propertyInfo, dbColumnName); } } return(mapper); }
protected virtual void Initializer(string connectionString, string tableName, ModelToTableMapper <T> mapper, IList <string> updateOf, DmlTriggerType dmlTriggerType, bool automaticDatabaseObjectsTeardown, string namingConventionForDatabaseObjects) { if (mapper != null && mapper.Count() == 0) { throw new ModelToTableMapperException("Empty mapper"); } if (!dmlTriggerType.HasFlag(DmlTriggerType.Update) && !dmlTriggerType.HasFlag(DmlTriggerType.All)) { if (updateOf != null && updateOf.Any()) { throw new DmlTriggerTypeException("updateOf parameter can be specified only if DmlTriggerType parameter contains DmlTriggerType.Update too, not for DmlTriggerType.Delete or DmlTriggerType.Insert only."); } } this.TraceLevel = TraceLevel.Off; CreateMirrorTable(connectionString, updateOf, tableName, namingConventionForDatabaseObjects); _connectionString = connectionString; _mapper = mapper ?? this.GetModelMapperFromColumnDataAnnotation(); _updateOf = updateOf; _userInterestedColumns = GetUserInterestedColumns(updateOf); _automaticDatabaseObjectsTeardown = automaticDatabaseObjectsTeardown; _dataBaseObjectsNamingConvention = GeneratedataBaseObjectsNamingConvention(namingConventionForDatabaseObjects); _needsToCreateDatabaseObjects = CheckIfNeedsToCreateDatabaseObjects(); _dmlTriggerType = dmlTriggerType; }
protected TableDependency(string connectionString, string tableName, ModelToTableMapper <T> mapper, UpdateOfModel <T> updateOf, DmlTriggerType dmlTriggerType) { this.TableDependencyCommonSettings(connectionString, tableName); this.Initializer(connectionString, tableName, mapper, this.GetColumnNameListFromUpdateOfModel(updateOf), dmlTriggerType); }
protected TableDependency(string connectionString, string tableName, ModelToTableMapper <T> mapper, UpdateOfModel <T> updateOf, DmlTriggerType dmlTriggerType, bool automaticDatabaseObjectsTeardown, string namingConventionForDatabaseObjects = null) { this.TableDependencyCommonSettings(connectionString, tableName); this.Initializer(connectionString, tableName, mapper, this.GetColumnNameListFromUpdateOfModel(updateOf), dmlTriggerType, automaticDatabaseObjectsTeardown, namingConventionForDatabaseObjects); }
protected TableDependency(string connectionString, string tableName, ModelToTableMapper <T> mapper, IList <string> updateOf, DmlTriggerType dmlTriggerType) { this.TableDependencyCommonSettings(connectionString, tableName); this.Initializer(connectionString, tableName, mapper, updateOf, dmlTriggerType); }