public void UpdateColumnInfoOnModelCreating(IDbSetInfo dbSetInfo, ColumnInfo columnInfo, EntityTypeBuilder entityBuilder, IShamanLogger logger) { const string source = nameof(SqlServerReflectionService) + "." + nameof(UpdateColumnInfoOnModelCreating); if (!UseDataType) { return; } if (columnInfo.ClrProperty?.PropertyType != typeof(string)) { return; } var modelInfo = dbSetInfo.Model; var collation = GetCollation(columnInfo, dbSetInfo, modelInfo); if (string.IsNullOrEmpty(collation)) { logger.Log(source, $"Column {dbSetInfo.GetSqlTableName()}.{columnInfo.PropertyName} has no SQL collation info"); return; } var isUnicode = columnInfo.IsUnicode ?? modelInfo.DefaultIsUnicodeText; var sqlDataType = SqlServerFixerService.MkStringType(isUnicode, columnInfo.MaxLength, collation); var action = $"{columnInfo.PropertyName}.HasColumnType(\"{sqlDataType}\")"; logger.LogCalling(source, dbSetInfo.EntityType, action); entityBuilder.Property(columnInfo.PropertyName).HasColumnType(sqlDataType); }
public void UpdateColumnInfoInModelInfo(ColumnInfo columnInfo, IDbSetInfo dbSetInfo, IShamanLogger logger) { if (columnInfo.IsNotMapped || columnInfo.IsNavigationProperty) { return; } var propertyInfo = columnInfo.ClrProperty; if (propertyInfo == null) { return; } var attribute = propertyInfo.GetCustomAttribute <NavigationPropertyAttribute>(); if (attribute != null) { return; } if (propertyInfo.PropertyType == typeof(string) || propertyInfo.PropertyType.IsEnum || propertyInfo.PropertyType.IsPrimitive) { return; } if (IsEntityType(propertyInfo.PropertyType)) { columnInfo.IsNavigationProperty = true; } else if (IsListOfEntityType(propertyInfo.PropertyType)) { columnInfo.IsNavigationProperty = true; } }
public void UpdateColumnInfoOnModelCreating(IDbSetInfo dbSetInfo, ColumnInfo columnInfo, EntityTypeBuilder entityBuilder, IShamanLogger logger) { const string source = nameof(DefaultValueColumnInfoUpdateService) + "." + nameof(UpdateColumnInfoOnModelCreating); var dv = columnInfo.DefaultValue; if (columnInfo.DefaultValue == null) { return; } string action; switch (dv.Kind) { case ValueInfoKind.Clr: action = $"{columnInfo.PropertyName}.HasDefaultValue(\"{columnInfo.DefaultValue.ClrValue}\")"; logger.LogCalling(source, dbSetInfo.EntityType, action); entityBuilder.Property(columnInfo.PropertyName).HasDefaultValue(columnInfo.DefaultValue.ClrValue); break; case ValueInfoKind.Sql: action = $"{columnInfo.PropertyName}.HasDefaultValueSql(\"{columnInfo.DefaultValue.SqlValue}\")"; logger.LogCalling(source, dbSetInfo.EntityType, action); entityBuilder.Property(columnInfo.PropertyName).HasDefaultValueSql(columnInfo.DefaultValue.SqlValue); break; default: throw new ArgumentOutOfRangeException(); } }
public void UpdateColumnInfoInModelInfo(ColumnInfo columnInfo, IDbSetInfo dbSetInfo, IShamanLogger logger) { var attribute = columnInfo.ClrProperty?.GetCustomAttribute <NavigationPropertyAttribute>(); if (attribute == null) { return; } Action <string> log = txt => logger.Log(typeof(NavigationPropertyAttributeUpdater), nameof(UpdateColumnInfoOnModelCreating), txt); var targetType = attribute.ForceNavigation ? "navigation" : "non-navigation"; if (columnInfo.IsNavigationProperty == attribute.ForceNavigation) { log( $"column {columnInfo.ColumnName} has been already set as {targetType} property. NavigationPropertyAttribute is not necessary."); } else { columnInfo.IsNavigationProperty = attribute.ForceNavigation; log($"column {columnInfo.ColumnName} is {targetType} property because of NavigationPropertyAttribute"); } }
public void UpdateColumnInfoInModelInfo(ColumnInfo columnInfo, IDbSetInfo dbSetInfo, IShamanLogger logger) { var notMappedAttribute = columnInfo.ClrProperty?.GetCustomAttribute <KeyAttribute>(); columnInfo.IsInPrimaryKey = notMappedAttribute != null; // todo : log }
public void UpdateColumnInfoInModelInfo(ColumnInfo columnInfo, IDbSetInfo dbSetInfo, IShamanLogger logger) { if (columnInfo.ClrProperty?.GetCustomAttribute <NotMappedAttribute>() != null) { columnInfo.IsNotMapped = true; } // todo log NotMappedAttributeUpdater.UpdateColumnInfo }
public void UpdateColumnInfoInModelInfo(ColumnInfo columnInfo, IDbSetInfo dbSetInfo, IShamanLogger logger) { if (columnInfo.ClrProperty?.GetCustomAttribute <InversePropertyAttribute>() != null) { columnInfo.IsNavigationProperty = true; } // todo log }
public void UpdateColumnInfoInModelInfo(ColumnInfo columnInfo, IDbSetInfo dbSetInfo, IShamanLogger logger) { if (columnInfo.ClrProperty?.GetCustomAttribute <ForeignKeyAttribute>() != null) { columnInfo.IsNavigationProperty = true; } // todo log // todo does ForeignKeyAttribute always means IsNavigationProperty = true ? }
public void UpdateColumnInfoInModelInfo(ColumnInfo columnInfo, IDbSetInfo dbSetInfo, IShamanLogger logger) { var attribute = columnInfo.ClrProperty?.GetCustomAttribute <DefaultValueAttribute>(); if (attribute != null) { columnInfo.DefaultValue = ValueInfo.FromClrValue(attribute.Value); } // todo: log }
public void UpdateColumnInfoInModelInfo(ColumnInfo columnInfo, IDbSetInfo dbSetInfo, IShamanLogger logger) { var attribute = columnInfo.ClrProperty?.GetCustomAttribute <DefaultValueSqlAttribute>(); if (!string.IsNullOrEmpty(attribute?.DefaultValueSql)) { columnInfo.DefaultValue = ValueInfo.FromSqlValue(attribute.DefaultValueSql); } // todo: log }
public void UpdateColumnInfoInModelInfo(ColumnInfo columnInfo, IDbSetInfo dbSetInfo, IShamanLogger logger) { var attribute = columnInfo.ClrProperty?.GetCustomAttribute <MaxLengthAttribute>(); if (attribute == null) { return; } columnInfo.MaxLength = attribute.Length; // todo log MaxLengthAttributeUpdater.UpdateColumnInfo }
public void UpdateColumnInfoInModelInfo(ColumnInfo columnInfo, IDbSetInfo dbSetInfo, IShamanLogger logger) { var indexAttribute = columnInfo.ClrProperty?.GetCustomAttribute <UnicodeTextAttribute>(); if (indexAttribute == null) { return; } logger.Log(typeof(UnicodeTextAttribute), nameof(UpdateColumnInfoOnModelCreating), $"Set IsUnicode={indexAttribute.IsUnicode}"); columnInfo.IsUnicode = indexAttribute.IsUnicode; }
public void UpdateColumnInfoInModelInfo(ColumnInfo columnInfo, IDbSetInfo dbSetInfo, IShamanLogger logger) { var indexAttribute = columnInfo.ClrProperty?.GetCustomAttribute <DecimalTypeAttribute>(); if (indexAttribute == null) { return; } logger.Log(typeof(DecimalTypeAttributeUpdater), nameof(UpdateColumnInfoOnModelCreating), $"Set MaxLength={indexAttribute.Length}, DecimalPlaces={indexAttribute.DecimalPlaces} for column '{columnInfo.ColumnName}'"); columnInfo.MaxLength = indexAttribute.Length; columnInfo.DecimalPlaces = indexAttribute.DecimalPlaces; }
public void UpdateColumnInfoOnModelCreating(IDbSetInfo dbSetInfo, ColumnInfo columnInfo, EntityTypeBuilder entityBuilder, IShamanLogger logger) { const string name = nameof(UnicodeColumnInfoUpdateService) + "." + nameof(UpdateColumnInfoOnModelCreating); if (columnInfo.IsUnicode == null) { return; } var action = $"IsUnicode({columnInfo.IsUnicode})"; logger.LogCalling(name, dbSetInfo.EntityType, action); entityBuilder.Property(columnInfo.PropertyName).IsUnicode(columnInfo.IsUnicode.Value); }
public void UpdateColumnInfoInModelInfo(ColumnInfo columnInfo, IDbSetInfo dbSetInfo, IShamanLogger logger) { var at = columnInfo.ClrProperty?.GetCustomAttribute <DatabaseGeneratedAttribute>(); if (at == null) { return; } logger.Log( typeof(DatabaseGeneratedAttributeUpdater), nameof(UpdateColumnInfoOnModelCreating), $"Set IsDatabaseGenerated=true and DatabaseGeneratedOption.Identity for column {columnInfo.ColumnName}"); columnInfo.IsDatabaseGenerated = true; columnInfo.IsIdentity = at.DatabaseGeneratedOption == DatabaseGeneratedOption.Identity; }
public void UpdateColumnInfoOnModelCreating(IDbSetInfo dbSetInfo, ColumnInfo columnInfo, EntityTypeBuilder entityBuilder, IShamanLogger logger) { const string name = nameof(DecimalPlacesColumnInfoUpdateService) + "." + nameof(UpdateColumnInfoOnModelCreating); if (columnInfo.MaxLength == null || columnInfo.DecimalPlaces == null) { return; } var type = $"decimal({columnInfo.MaxLength},{columnInfo.DecimalPlaces})"; var action = $"{columnInfo.PropertyName}.HasColumnType(\"{type}\")"; logger.LogCalling(name, dbSetInfo.EntityType, action); entityBuilder.Property(columnInfo.PropertyName).HasColumnType(type); }
public void UpdateColumnInfoInModelInfo(ColumnInfo columnInfo, IDbSetInfo dbSetInfo, IShamanLogger logger) { if (columnInfo.ClrProperty?.GetCustomAttribute <TimestampAttribute>() == null) { return; } var logPrefix = $"Set {dbSetInfo.TableName}.{columnInfo.ColumnName}"; const string logSource = nameof(TimestampAttributeUpdater) + "." + nameof(UpdateColumnInfoOnModelCreating); columnInfo.IsTimestamp = true; logger.Log(logSource, $"{logPrefix}.IsTimestamp=true"); columnInfo.IsDatabaseGenerated = true; logger.Log(logSource, $"{logPrefix}.IsDatabaseGenerated=true"); }
public void UpdateColumnInfoInModelInfo(ColumnInfo columnInfo, IDbSetInfo dbSetInfo, IShamanLogger logger) { var attribute = columnInfo.ClrProperty?.GetCustomAttribute <RequiredAttribute>(); if (attribute == null) { return; } var logPrefix = $"Set {dbSetInfo.TableName}.{columnInfo.ColumnName}"; const string logSource = nameof(RequiredAttributeUpdater) + "." + nameof(UpdateColumnInfoInModelInfo); columnInfo.NotNull = true; logger.Log(logSource, $"{logPrefix}.NotNull=true"); }
public void UpdateColumnInfoInModelInfo(ColumnInfo columnInfo, IDbSetInfo dbSetInfo, IShamanLogger logger) { var propertyInfo = columnInfo.ClrProperty; if (propertyInfo?.PropertyType != typeof(string)) { return; } var collation = GetCollation(propertyInfo); if (string.IsNullOrEmpty(collation)) { return; } var target = $"column {dbSetInfo.GetSqlTableName()}.{columnInfo.ColumnName}"; UpdateAnnotation(columnInfo, collation, logger, target); }
public void UpdateColumnInfoInModelInfo(ColumnInfo columnInfo, IDbSetInfo dbSetInfo, IShamanLogger logger) { var indexAttributes = columnInfo.ClrProperty?.GetCustomAttributes <AbstractIndexAttribute>()?.ToArray(); if (indexAttributes == null || !indexAttributes.Any()) { return; } foreach (var indexAttribute in indexAttributes) { var indexInfo = GetOrCreateColumnIndexInfo(columnInfo, indexAttribute) .WithInfoFromAbstractIndexAttribute(indexAttribute) .WithInfoFromUniqueIndexAttribute(indexAttribute as UniqueIndexAttribute) .WithInfoFromFullTextIndexAttribute(indexAttribute as FullTextIndexAttribute); logger.Log(typeof(IndexAttributeUpdater), nameof(UpdateColumnInfoOnModelCreating), $"Set indexInfo: Order={indexInfo.Order}, IsDescending={indexInfo.IsDescending}, IndexType={indexInfo.IndexType}"); } }
public void UpdateColumnInfoInModelInfo(ColumnInfo columnInfo, IDbSetInfo dbSetInfo, IShamanLogger logger) { var attribute = columnInfo.ClrProperty?.GetCustomAttribute <ColumnAttribute>(); if (attribute == null) { return; } const string logSource = nameof(ColumnInfoColumnAttributeUpdater) + "." + nameof(UpdateColumnInfoInModelInfo); if (!string.IsNullOrEmpty(attribute.Name)) { columnInfo.ColumnName = attribute.Name; logger.Log(logSource, $"Set {dbSetInfo.TableName}.{columnInfo.ColumnName}.ColumnName='{columnInfo.ColumnName}'"); } if (attribute.Order >= 0) { columnInfo.ForceFieldOrder = attribute.Order; logger.Log(logSource, $"Set {dbSetInfo.TableName}.{columnInfo.ColumnName}.ForceFieldOrder={columnInfo.ForceFieldOrder}"); } }
public void UpdateColumnInfoOnModelCreating(IDbSetInfo dbSetInfo, ColumnInfo columnInfo, EntityTypeBuilder entityBuilder, IShamanLogger logger) { }
public static string GetSqlTableName(this IDbSetInfo tn) { return(Escape(tn.Schema, tn.TableName)); }
public void UpdateColumnInfoInModelInfo(ColumnInfo columnInfo, IDbSetInfo dbSetInfo, IShamanLogger logger) { }