Browse Source

Merge pull request #8898 from abpframework/liangshiwei/efcore-extension

Allow to customize EF Core mapping of entity and dbContext of an existing module
pull/9244/head
Halil İbrahim Kalkan 5 years ago
committed by GitHub
parent
commit
2a22ebdd34
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs
  2. 5
      framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/Modeling/AbpEntityTypeBuilderExtensions.cs
  3. 14
      framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/Modeling/AbpModelBuilderObjectExtensions.cs
  4. 70
      framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/ObjectExtending/EfCoreObjectExtensionInfoExtensions.cs
  5. 74
      framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/ObjectExtending/EfCoreObjectExtensionManagerExtensions.cs
  6. 39
      framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/ObjectExtending/ObjectExtensionInfoEfCoreMappingOptions.cs
  7. 2
      framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionInfo.cs
  8. 6
      framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManager.cs
  9. 28
      framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Domain/TestEntityExtensionConfigurator.cs
  10. 9
      framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/TestApp/EntityFrameworkCore/TestAppDbContext.cs
  11. 14
      modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingDbContextModelBuilderExtensions.cs
  12. 4
      modules/background-jobs/src/Volo.Abp.BackgroundJobs.EntityFrameworkCore/Volo/Abp/BackgroundJobs/EntityFrameworkCore/BackgroundJobsDbContextModelCreatingExtensions.cs
  13. 8
      modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.EntityFrameworkCore/Volo/Abp/BlobStoring/Database/EntityFrameworkCore/BlobStoringDbContextModelCreatingExtensions.cs
  14. 14
      modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/EntityFrameworkCore/BloggingDbContextModelBuilderExtensions.cs
  15. 28
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs
  16. 8
      modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/EntityFrameworkCore/DocsDbContextModelBuilderExtensions.cs
  17. 4
      modules/feature-management/src/Volo.Abp.FeatureManagement.EntityFrameworkCore/Volo/Abp/FeatureManagement/EntityFrameworkCore/FeatureManagementDbContextModelCreatingExtensions.cs
  18. 28
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityDbContextModelBuilderExtensions.cs
  19. 48
      modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerDbContextModelCreatingExtensions.cs
  20. 6
      modules/permission-management/src/Volo.Abp.PermissionManagement.EntityFrameworkCore/Volo/Abp/PermissionManagement/EntityFrameworkCore/AbpPermissionManagementDbContextModelBuilderExtensions.cs
  21. 4
      modules/setting-management/src/Volo.Abp.SettingManagement.EntityFrameworkCore/Volo/Abp/SettingManagement/EntityFrameworkCore/SettingManagementDbContextModelBuilderExtensions.cs
  22. 6
      modules/tenant-management/src/Volo.Abp.TenantManagement.EntityFrameworkCore/Volo/Abp/TenantManagement/EntityFrameworkCore/AbpTenantManagementDbContextModelCreatingExtensions.cs

1
framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs

@ -86,7 +86,6 @@ namespace Volo.Abp.EntityFrameworkCore
protected AbpDbContext(DbContextOptions<TDbContext> options) protected AbpDbContext(DbContextOptions<TDbContext> options)
: base(options) : base(options)
{ {
} }
protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder)

5
framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/Modeling/AbpEntityTypeBuilderExtensions.cs

@ -82,6 +82,11 @@ namespace Volo.Abp.EntityFrameworkCore.Modeling
} }
} }
public static void ApplyObjectExtensionMappings(this EntityTypeBuilder b)
{
ObjectExtensionManager.Instance.ConfigureEfCoreEntity(b);
}
public static void ConfigureSoftDelete<T>(this EntityTypeBuilder<T> b) public static void ConfigureSoftDelete<T>(this EntityTypeBuilder<T> b)
where T : class, ISoftDelete where T : class, ISoftDelete
{ {

14
framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/Modeling/AbpModelBuilderObjectExtensions.cs

@ -0,0 +1,14 @@
using Microsoft.EntityFrameworkCore;
using Volo.Abp.ObjectExtending;
namespace Volo.Abp.EntityFrameworkCore.Modeling
{
public static class AbpModelBuilderObjectExtensions
{
public static void TryConfigureObjectExtensions<TDbContext>(this ModelBuilder modelBuilder)
where TDbContext : DbContext
{
ObjectExtensionManager.Instance.ConfigureEfCoreDbContext<TDbContext>(modelBuilder);
}
}
}

70
framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/ObjectExtending/EfCoreObjectExtensionInfoExtensions.cs

@ -1,11 +1,17 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations; using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Volo.Abp.ObjectExtending namespace Volo.Abp.ObjectExtending
{ {
public static class EfCoreObjectExtensionInfoExtensions public static class EfCoreObjectExtensionInfoExtensions
{ {
public const string EfCoreDbContextConfigurationName = "EfCoreDbContextMapping";
public const string EfCoreEntityConfigurationName = "EfCoreEntityMapping";
[Obsolete("Use MapEfCoreProperty with EntityTypeAndPropertyBuildAction parameters.")] [Obsolete("Use MapEfCoreProperty with EntityTypeAndPropertyBuildAction parameters.")]
public static ObjectExtensionInfo MapEfCoreProperty<TProperty>( public static ObjectExtensionInfo MapEfCoreProperty<TProperty>(
[NotNull] this ObjectExtensionInfo objectExtensionInfo, [NotNull] this ObjectExtensionInfo objectExtensionInfo,
@ -71,5 +77,69 @@ namespace Volo.Abp.ObjectExtending
} }
); );
} }
public static ObjectExtensionInfo MapEfCoreEntity(
[NotNull] this ObjectExtensionInfo objectExtensionInfo,
[NotNull] Action<EntityTypeBuilder> entityTypeBuildAction)
{
Check.NotNull(objectExtensionInfo, nameof(objectExtensionInfo));
var mappingOptionList = new List<ObjectExtensionInfoEfCoreMappingOptions>
{
new ObjectExtensionInfoEfCoreMappingOptions(
objectExtensionInfo,
entityTypeBuildAction)
};
objectExtensionInfo.Configuration.AddOrUpdate(EfCoreEntityConfigurationName, mappingOptionList,
(k, v) =>
{
v.As<List<ObjectExtensionInfoEfCoreMappingOptions>>().Add(mappingOptionList.First());
return v;
});
return objectExtensionInfo;
}
public static ObjectExtensionInfo MapEfCoreDbContext(
[NotNull] this ObjectExtensionInfo objectExtensionInfo,
[NotNull] Action<ModelBuilder> modelBuildAction)
{
Check.NotNull(objectExtensionInfo, nameof(objectExtensionInfo));
var mappingOptionList = new List<ObjectExtensionInfoEfCoreMappingOptions>
{
new ObjectExtensionInfoEfCoreMappingOptions(
objectExtensionInfo,
modelBuildAction)
};
objectExtensionInfo.Configuration.AddOrUpdate(EfCoreDbContextConfigurationName, mappingOptionList,
(k, v) =>
{
v.As<List<ObjectExtensionInfoEfCoreMappingOptions>>().Add(mappingOptionList.First());
return v;
});
return objectExtensionInfo;
}
public static List<ObjectExtensionInfoEfCoreMappingOptions> GetEfCoreEntityMappings(
[NotNull] this ObjectExtensionInfo objectExtensionInfo)
{
Check.NotNull(objectExtensionInfo, nameof(objectExtensionInfo));
return !objectExtensionInfo.Configuration.TryGetValue(EfCoreEntityConfigurationName, out var options) ?
new List<ObjectExtensionInfoEfCoreMappingOptions>() : options.As<List<ObjectExtensionInfoEfCoreMappingOptions>>();
}
public static List<ObjectExtensionInfoEfCoreMappingOptions> GetEfCoreDbContextMappings(
[NotNull] this ObjectExtensionInfo objectExtensionInfo)
{
Check.NotNull(objectExtensionInfo, nameof(objectExtensionInfo));
return !objectExtensionInfo.Configuration.TryGetValue(EfCoreDbContextConfigurationName, out var options) ?
new List<ObjectExtensionInfoEfCoreMappingOptions>() : options.As<List<ObjectExtensionInfoEfCoreMappingOptions>>();
}
} }
} }

74
framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/ObjectExtending/EfCoreObjectExtensionManagerExtensions.cs

@ -1,5 +1,6 @@
using System; using System;
using JetBrains.Annotations; using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Volo.Abp.Data; using Volo.Abp.Data;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
@ -8,6 +9,45 @@ namespace Volo.Abp.ObjectExtending
{ {
public static class EfCoreObjectExtensionManagerExtensions public static class EfCoreObjectExtensionManagerExtensions
{ {
public static ObjectExtensionManager MapEfCoreDbContext<TDbContext>(
[NotNull] this ObjectExtensionManager objectExtensionManager,
[NotNull] Action<ModelBuilder> modelBuilderAction)
where TDbContext : DbContext
{
return objectExtensionManager.AddOrUpdate(
typeof(TDbContext),
options =>
{
options.MapEfCoreDbContext(modelBuilderAction);
});
}
public static ObjectExtensionManager MapEfCoreEntity<TEntity>(
[NotNull] this ObjectExtensionManager objectExtensionManager,
[NotNull] Action<EntityTypeBuilder> entityTypeBuildAction)
where TEntity : IEntity
{
return MapEfCoreEntity(
objectExtensionManager,
typeof(TEntity),
entityTypeBuildAction);
}
public static ObjectExtensionManager MapEfCoreEntity(
[NotNull] this ObjectExtensionManager objectExtensionManager,
[NotNull] Type entityType,
[NotNull] Action<EntityTypeBuilder> entityTypeBuildAction)
{
Check.NotNull(objectExtensionManager, nameof(objectExtensionManager));
return objectExtensionManager.AddOrUpdate(
entityType,
options =>
{
options.MapEfCoreEntity(entityTypeBuildAction);
});
}
public static ObjectExtensionManager MapEfCoreProperty<TEntity, TProperty>( public static ObjectExtensionManager MapEfCoreProperty<TEntity, TProperty>(
[NotNull] this ObjectExtensionManager objectExtensionManager, [NotNull] this ObjectExtensionManager objectExtensionManager,
[NotNull] string propertyName) [NotNull] string propertyName)
@ -32,10 +72,7 @@ namespace Volo.Abp.ObjectExtending
entityType, entityType,
propertyType, propertyType,
propertyName, propertyName,
options => options => { options.MapEfCore(); }
{
options.MapEfCore();
}
); );
} }
@ -126,6 +163,13 @@ namespace Volo.Abp.ObjectExtending
return; return;
} }
var efCoreEntityMappings = objectExtension.GetEfCoreEntityMappings();
foreach (var efCoreEntityMapping in efCoreEntityMappings)
{
efCoreEntityMapping.EntityTypeBuildAction?.Invoke(typeBuilder);
}
foreach (var property in objectExtension.GetProperties()) foreach (var property in objectExtension.GetProperties())
{ {
var efCoreMapping = property.GetEfCoreMappingOrNull(); var efCoreMapping = property.GetEfCoreMappingOrNull();
@ -148,5 +192,27 @@ namespace Volo.Abp.ObjectExtending
#pragma warning restore 618 #pragma warning restore 618
} }
} }
public static void ConfigureEfCoreDbContext<TDbContext>(
[NotNull] this ObjectExtensionManager objectExtensionManager,
[NotNull] ModelBuilder modelBuilder)
where TDbContext : DbContext
{
Check.NotNull(objectExtensionManager, nameof(objectExtensionManager));
Check.NotNull(modelBuilder, nameof(modelBuilder));
var objectExtension = objectExtensionManager.GetOrNull(typeof(TDbContext));
if (objectExtension == null)
{
return;
}
var efCoreDbContextMappings = objectExtension.GetEfCoreDbContextMappings();
foreach (var efCoreDbContextMapping in efCoreDbContextMappings)
{
efCoreDbContextMapping.ModelBuildAction?.Invoke(modelBuilder);
}
}
} }
} }

39
framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/ObjectExtending/ObjectExtensionInfoEfCoreMappingOptions.cs

@ -0,0 +1,39 @@
using System;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Volo.Abp.ObjectExtending
{
public class ObjectExtensionInfoEfCoreMappingOptions
{
[NotNull]
public ObjectExtensionInfo ObjectExtension { get; }
[CanBeNull]
public Action<EntityTypeBuilder> EntityTypeBuildAction { get; set; }
[CanBeNull]
public Action<ModelBuilder> ModelBuildAction { get; set; }
public ObjectExtensionInfoEfCoreMappingOptions(
[NotNull] ObjectExtensionInfo objectExtension,
[NotNull] Action<EntityTypeBuilder> entityTypeBuildAction)
{
ObjectExtension = Check.NotNull(objectExtension, nameof(objectExtension));
EntityTypeBuildAction = Check.NotNull(entityTypeBuildAction, nameof(entityTypeBuildAction));
EntityTypeBuildAction = entityTypeBuildAction;
}
public ObjectExtensionInfoEfCoreMappingOptions(
[NotNull] ObjectExtensionInfo objectExtension,
[NotNull] Action<ModelBuilder> modelBuildAction)
{
ObjectExtension = Check.NotNull(objectExtension, nameof(objectExtension));
ModelBuildAction = Check.NotNull(modelBuildAction, nameof(modelBuildAction));
ModelBuildAction = modelBuildAction;
}
}
}

2
framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionInfo.cs

@ -24,7 +24,7 @@ namespace Volo.Abp.ObjectExtending
public ObjectExtensionInfo([NotNull] Type type) public ObjectExtensionInfo([NotNull] Type type)
{ {
Type = Check.AssignableTo<IHasExtraProperties>(type, nameof(type)); Type = Check.NotNull(type, nameof(type));
Properties = new ConcurrentDictionary<string, ObjectExtensionPropertyInfo>(); Properties = new ConcurrentDictionary<string, ObjectExtensionPropertyInfo>();
Configuration = new ConcurrentDictionary<object, object>(); Configuration = new ConcurrentDictionary<object, object>();
Validators = new List<Action<ObjectExtensionValidationContext>>(); Validators = new List<Action<ObjectExtensionValidationContext>>();

6
framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManager.cs

@ -25,7 +25,6 @@ namespace Volo.Abp.ObjectExtending
[NotNull] [NotNull]
public virtual ObjectExtensionManager AddOrUpdate<TObject>( public virtual ObjectExtensionManager AddOrUpdate<TObject>(
[CanBeNull] Action<ObjectExtensionInfo> configureAction = null) [CanBeNull] Action<ObjectExtensionInfo> configureAction = null)
where TObject : IHasExtraProperties
{ {
return AddOrUpdate(typeof(TObject), configureAction); return AddOrUpdate(typeof(TObject), configureAction);
} }
@ -50,8 +49,6 @@ namespace Volo.Abp.ObjectExtending
[NotNull] Type type, [NotNull] Type type,
[CanBeNull] Action<ObjectExtensionInfo> configureAction = null) [CanBeNull] Action<ObjectExtensionInfo> configureAction = null)
{ {
Check.AssignableTo<IHasExtraProperties>(type, nameof(type));
var extensionInfo = ObjectsExtensions.GetOrAdd( var extensionInfo = ObjectsExtensions.GetOrAdd(
type, type,
_ => new ObjectExtensionInfo(type) _ => new ObjectExtensionInfo(type)
@ -64,7 +61,6 @@ namespace Volo.Abp.ObjectExtending
[CanBeNull] [CanBeNull]
public virtual ObjectExtensionInfo GetOrNull<TObject>() public virtual ObjectExtensionInfo GetOrNull<TObject>()
where TObject : IHasExtraProperties
{ {
return GetOrNull(typeof(TObject)); return GetOrNull(typeof(TObject));
} }
@ -72,8 +68,6 @@ namespace Volo.Abp.ObjectExtending
[CanBeNull] [CanBeNull]
public virtual ObjectExtensionInfo GetOrNull([NotNull] Type type) public virtual ObjectExtensionInfo GetOrNull([NotNull] Type type)
{ {
Check.AssignableTo<IHasExtraProperties>(type, nameof(type));
return ObjectsExtensions.GetOrDefault(type); return ObjectsExtensions.GetOrDefault(type);
} }

28
framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Domain/TestEntityExtensionConfigurator.cs

@ -1,6 +1,8 @@
using System; using System;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Volo.Abp.ObjectExtending; using Volo.Abp.ObjectExtending;
using Volo.Abp.TestApp.Domain; using Volo.Abp.TestApp.Domain;
using Volo.Abp.TestApp.EntityFrameworkCore;
using Volo.Abp.Threading; using Volo.Abp.Threading;
namespace Volo.Abp.EntityFrameworkCore.Domain namespace Volo.Abp.EntityFrameworkCore.Domain
@ -35,7 +37,31 @@ namespace Volo.Abp.EntityFrameworkCore.Domain
"EnumNumberString" "EnumNumberString"
).MapEfCoreProperty<City, ExtraProperties_Tests.Color>( ).MapEfCoreProperty<City, ExtraProperties_Tests.Color>(
"EnumLiteral" "EnumLiteral"
); ).MapEfCoreEntity<City>(b =>
{
b.As<EntityTypeBuilder<City>>()
.Property(x=>x.Name).IsRequired();
}).MapEfCoreEntity<City>(b =>
{
b.As<EntityTypeBuilder<City>>()
.Property(x=>x.Name).HasMaxLength(200);
}).MapEfCoreEntity(typeof(Person), b =>
{
b.As<EntityTypeBuilder<Person>>()
.HasIndex(x=>x.Birthday);
});
ObjectExtensionManager.Instance.MapEfCoreDbContext<TestAppDbContext>(b =>
{
b.Entity<City>().Property(x => x.Name).IsRequired();
});
ObjectExtensionManager.Instance.MapEfCoreDbContext<TestAppDbContext>(b =>
{
b.Entity<Author>().Property(x => x.Name).IsRequired();
});
}); });
} }
} }

9
framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/TestApp/EntityFrameworkCore/TestAppDbContext.cs

@ -1,6 +1,7 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.Modeling;
using Volo.Abp.EntityFrameworkCore.TestApp.FourthContext; using Volo.Abp.EntityFrameworkCore.TestApp.FourthContext;
using Volo.Abp.EntityFrameworkCore.TestApp.ThirdDbContext; using Volo.Abp.EntityFrameworkCore.TestApp.ThirdDbContext;
using Volo.Abp.TestApp.Domain; using Volo.Abp.TestApp.Domain;
@ -41,6 +42,8 @@ namespace Volo.Abp.TestApp.EntityFrameworkCore
modelBuilder.Entity<Phone>(b => modelBuilder.Entity<Phone>(b =>
{ {
b.HasKey(p => new {p.PersonId, p.Number}); b.HasKey(p => new {p.PersonId, p.Number});
b.ApplyObjectExtensionMappings();
}); });
modelBuilder modelBuilder
@ -48,6 +51,8 @@ namespace Volo.Abp.TestApp.EntityFrameworkCore
{ {
p.HasNoKey(); p.HasNoKey();
p.ToView("View_PersonView"); p.ToView("View_PersonView");
p.ApplyObjectExtensionMappings();
}); });
modelBuilder.Entity<City>(b => modelBuilder.Entity<City>(b =>
@ -57,7 +62,11 @@ namespace Volo.Abp.TestApp.EntityFrameworkCore
d.WithOwner().HasForeignKey(x => x.CityId); d.WithOwner().HasForeignKey(x => x.CityId);
d.HasKey(x => new {x.CityId, x.Name}); d.HasKey(x => new {x.CityId, x.Name});
}); });
b.ApplyObjectExtensionMappings();
}); });
modelBuilder.TryConfigureObjectExtensions<TestAppDbContext>();
} }
} }
} }

14
modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingDbContextModelBuilderExtensions.cs

@ -39,7 +39,7 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore
if (builder.IsUsingOracle()) { AuditLogConsts.MaxExceptionsLengthValue = 2000; } if (builder.IsUsingOracle()) { AuditLogConsts.MaxExceptionsLengthValue = 2000; }
b.Property(x => x.Exceptions).HasMaxLength(AuditLogConsts.MaxExceptionsLengthValue).HasColumnName(nameof(AuditLog.Exceptions)); b.Property(x => x.Exceptions).HasMaxLength(AuditLogConsts.MaxExceptionsLengthValue).HasColumnName(nameof(AuditLog.Exceptions));
b.Property(x => x.Comments).HasMaxLength(AuditLogConsts.MaxCommentsLength).HasColumnName(nameof(AuditLog.Comments)); b.Property(x => x.Comments).HasMaxLength(AuditLogConsts.MaxCommentsLength).HasColumnName(nameof(AuditLog.Comments));
b.Property(x => x.ExecutionDuration).HasColumnName(nameof(AuditLog.ExecutionDuration)); b.Property(x => x.ExecutionDuration).HasColumnName(nameof(AuditLog.ExecutionDuration));
b.Property(x => x.ImpersonatorTenantId).HasColumnName(nameof(AuditLog.ImpersonatorTenantId)); b.Property(x => x.ImpersonatorTenantId).HasColumnName(nameof(AuditLog.ImpersonatorTenantId));
@ -53,6 +53,8 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore
b.HasIndex(x => new { x.TenantId, x.ExecutionTime }); b.HasIndex(x => new { x.TenantId, x.ExecutionTime });
b.HasIndex(x => new { x.TenantId, x.UserId, x.ExecutionTime }); b.HasIndex(x => new { x.TenantId, x.UserId, x.ExecutionTime });
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<AuditLogAction>(b => builder.Entity<AuditLogAction>(b =>
@ -67,9 +69,11 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore
b.Property(x => x.Parameters).HasMaxLength(AuditLogActionConsts.MaxParametersLength).HasColumnName(nameof(AuditLogAction.Parameters)); b.Property(x => x.Parameters).HasMaxLength(AuditLogActionConsts.MaxParametersLength).HasColumnName(nameof(AuditLogAction.Parameters));
b.Property(x => x.ExecutionTime).HasColumnName(nameof(AuditLogAction.ExecutionTime)); b.Property(x => x.ExecutionTime).HasColumnName(nameof(AuditLogAction.ExecutionTime));
b.Property(x => x.ExecutionDuration).HasColumnName(nameof(AuditLogAction.ExecutionDuration)); b.Property(x => x.ExecutionDuration).HasColumnName(nameof(AuditLogAction.ExecutionDuration));
b.HasIndex(x => new { x.AuditLogId }); b.HasIndex(x => new { x.AuditLogId });
b.HasIndex(x => new { x.TenantId, x.ServiceName, x.MethodName, x.ExecutionTime }); b.HasIndex(x => new { x.TenantId, x.ServiceName, x.MethodName, x.ExecutionTime });
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<EntityChange>(b => builder.Entity<EntityChange>(b =>
@ -89,6 +93,8 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore
b.HasIndex(x => new { x.AuditLogId }); b.HasIndex(x => new { x.AuditLogId });
b.HasIndex(x => new { x.TenantId, x.EntityTypeFullName, x.EntityId }); b.HasIndex(x => new { x.TenantId, x.EntityTypeFullName, x.EntityId });
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<EntityPropertyChange>(b => builder.Entity<EntityPropertyChange>(b =>
@ -103,7 +109,11 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore
b.Property(x => x.OriginalValue).HasMaxLength(EntityPropertyChangeConsts.MaxOriginalValueLength).HasColumnName(nameof(EntityPropertyChange.OriginalValue)); b.Property(x => x.OriginalValue).HasMaxLength(EntityPropertyChangeConsts.MaxOriginalValueLength).HasColumnName(nameof(EntityPropertyChange.OriginalValue));
b.HasIndex(x => new { x.EntityChangeId }); b.HasIndex(x => new { x.EntityChangeId });
b.ApplyObjectExtensionMappings();
}); });
builder.TryConfigureObjectExtensions<AbpAuditLoggingDbContext>();
} }
} }
} }

4
modules/background-jobs/src/Volo.Abp.BackgroundJobs.EntityFrameworkCore/Volo/Abp/BackgroundJobs/EntityFrameworkCore/BackgroundJobsDbContextModelCreatingExtensions.cs

@ -39,7 +39,11 @@ namespace Volo.Abp.BackgroundJobs.EntityFrameworkCore
b.Property(x => x.Priority).HasDefaultValue(BackgroundJobPriority.Normal); b.Property(x => x.Priority).HasDefaultValue(BackgroundJobPriority.Normal);
b.HasIndex(x => new { x.IsAbandoned, x.NextTryTime }); b.HasIndex(x => new { x.IsAbandoned, x.NextTryTime });
b.ApplyObjectExtensionMappings();
}); });
builder.TryConfigureObjectExtensions<BackgroundJobsDbContext>();
} }
} }
} }

8
modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.EntityFrameworkCore/Volo/Abp/BlobStoring/Database/EntityFrameworkCore/BlobStoringDbContextModelCreatingExtensions.cs

@ -30,6 +30,8 @@ namespace Volo.Abp.BlobStoring.Database.EntityFrameworkCore
b.HasMany<DatabaseBlob>().WithOne().HasForeignKey(p => p.ContainerId); b.HasMany<DatabaseBlob>().WithOne().HasForeignKey(p => p.ContainerId);
b.HasIndex(x => new {x.TenantId, x.Name}); b.HasIndex(x => new {x.TenantId, x.Name});
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<DatabaseBlob>(b => builder.Entity<DatabaseBlob>(b =>
@ -45,7 +47,11 @@ namespace Volo.Abp.BlobStoring.Database.EntityFrameworkCore
b.HasOne<DatabaseBlobContainer>().WithMany().HasForeignKey(p => p.ContainerId); b.HasOne<DatabaseBlobContainer>().WithMany().HasForeignKey(p => p.ContainerId);
b.HasIndex(x => new {x.TenantId, x.ContainerId, x.Name}); b.HasIndex(x => new {x.TenantId, x.ContainerId, x.Name});
b.ApplyObjectExtensionMappings();
}); });
builder.TryConfigureObjectExtensions<BlobStoringDbContext>();
} }
} }
} }

14
modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/EntityFrameworkCore/BloggingDbContextModelBuilderExtensions.cs

@ -38,6 +38,8 @@ namespace Volo.Blogging.EntityFrameworkCore
b.ConfigureByConvention(); b.ConfigureByConvention();
b.ConfigureAbpUser(); b.ConfigureAbpUser();
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<Blog>(b => builder.Entity<Blog>(b =>
@ -49,6 +51,8 @@ namespace Volo.Blogging.EntityFrameworkCore
b.Property(x => x.Name).IsRequired().HasMaxLength(BlogConsts.MaxNameLength).HasColumnName(nameof(Blog.Name)); b.Property(x => x.Name).IsRequired().HasMaxLength(BlogConsts.MaxNameLength).HasColumnName(nameof(Blog.Name));
b.Property(x => x.ShortName).IsRequired().HasMaxLength(BlogConsts.MaxShortNameLength).HasColumnName(nameof(Blog.ShortName)); b.Property(x => x.ShortName).IsRequired().HasMaxLength(BlogConsts.MaxShortNameLength).HasColumnName(nameof(Blog.ShortName));
b.Property(x => x.Description).IsRequired(false).HasMaxLength(BlogConsts.MaxDescriptionLength).HasColumnName(nameof(Blog.Description)); b.Property(x => x.Description).IsRequired(false).HasMaxLength(BlogConsts.MaxDescriptionLength).HasColumnName(nameof(Blog.Description));
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<Post>(b => builder.Entity<Post>(b =>
@ -67,6 +71,8 @@ namespace Volo.Blogging.EntityFrameworkCore
b.HasMany(p => p.Tags).WithOne().HasForeignKey(qt => qt.PostId); b.HasMany(p => p.Tags).WithOne().HasForeignKey(qt => qt.PostId);
b.HasOne<Blog>().WithMany().IsRequired().HasForeignKey(p => p.BlogId); b.HasOne<Blog>().WithMany().IsRequired().HasForeignKey(p => p.BlogId);
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<Comment>(b => builder.Entity<Comment>(b =>
@ -81,6 +87,8 @@ namespace Volo.Blogging.EntityFrameworkCore
b.HasOne<Comment>().WithMany().HasForeignKey(p => p.RepliedCommentId); b.HasOne<Comment>().WithMany().HasForeignKey(p => p.RepliedCommentId);
b.HasOne<Post>().WithMany().IsRequired().HasForeignKey(p => p.PostId); b.HasOne<Post>().WithMany().IsRequired().HasForeignKey(p => p.PostId);
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<Tag>(b => builder.Entity<Tag>(b =>
@ -94,6 +102,8 @@ namespace Volo.Blogging.EntityFrameworkCore
b.Property(x => x.UsageCount).HasColumnName(nameof(Tag.UsageCount)); b.Property(x => x.UsageCount).HasColumnName(nameof(Tag.UsageCount));
b.HasMany<PostTag>().WithOne().HasForeignKey(qt => qt.TagId); b.HasMany<PostTag>().WithOne().HasForeignKey(qt => qt.TagId);
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<PostTag>(b => builder.Entity<PostTag>(b =>
@ -106,7 +116,11 @@ namespace Volo.Blogging.EntityFrameworkCore
b.Property(x => x.TagId).HasColumnName(nameof(PostTag.TagId)); b.Property(x => x.TagId).HasColumnName(nameof(PostTag.TagId));
b.HasKey(x => new { x.PostId, x.TagId }); b.HasKey(x => new { x.PostId, x.TagId });
b.ApplyObjectExtensionMappings();
}); });
builder.TryConfigureObjectExtensions<BloggingDbContext>();
} }
} }
} }

28
modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs

@ -42,6 +42,8 @@ namespace Volo.CmsKit.EntityFrameworkCore
b.HasIndex(x => new { x.TenantId, x.UserName }); b.HasIndex(x => new { x.TenantId, x.UserName });
b.HasIndex(x => new { x.TenantId, x.Email }); b.HasIndex(x => new { x.TenantId, x.Email });
b.ApplyObjectExtensionMappings();
}); });
} }
else else
@ -63,6 +65,8 @@ namespace Volo.CmsKit.EntityFrameworkCore
b.HasIndex(x => new { x.TenantId, x.EntityType, x.EntityId, x.ReactionName }); b.HasIndex(x => new { x.TenantId, x.EntityType, x.EntityId, x.ReactionName });
b.HasIndex(x => new { x.TenantId, x.CreatorId, x.EntityType, x.EntityId, x.ReactionName }); b.HasIndex(x => new { x.TenantId, x.CreatorId, x.EntityType, x.EntityId, x.ReactionName });
b.ApplyObjectExtensionMappings();
}); });
} }
else else
@ -85,6 +89,8 @@ namespace Volo.CmsKit.EntityFrameworkCore
b.HasIndex(x => new { x.TenantId, x.EntityType, x.EntityId }); b.HasIndex(x => new { x.TenantId, x.EntityType, x.EntityId });
b.HasIndex(x => new { x.TenantId, x.RepliedCommentId }); b.HasIndex(x => new { x.TenantId, x.RepliedCommentId });
b.ApplyObjectExtensionMappings();
}); });
} }
else else
@ -105,6 +111,8 @@ namespace Volo.CmsKit.EntityFrameworkCore
r.Property(x => x.EntityId).IsRequired().HasMaxLength(RatingConsts.MaxEntityIdLength); r.Property(x => x.EntityId).IsRequired().HasMaxLength(RatingConsts.MaxEntityIdLength);
r.HasIndex(x => new { x.TenantId, x.EntityType, x.EntityId, x.CreatorId }); r.HasIndex(x => new { x.TenantId, x.EntityType, x.EntityId, x.CreatorId });
r.ApplyObjectExtensionMappings();
}); });
} }
else else
@ -128,6 +136,8 @@ namespace Volo.CmsKit.EntityFrameworkCore
x.TenantId, x.TenantId,
x.Name x.Name
}); });
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<EntityTag>(b => builder.Entity<EntityTag>(b =>
@ -142,6 +152,8 @@ namespace Volo.CmsKit.EntityFrameworkCore
b.Property(x => x.TagId).IsRequired(); b.Property(x => x.TagId).IsRequired();
b.HasIndex(x => new { x.TenantId, x.EntityId, x.TagId }); b.HasIndex(x => new { x.TenantId, x.EntityId, x.TagId });
b.ApplyObjectExtensionMappings();
}); });
} }
else else
@ -163,6 +175,8 @@ namespace Volo.CmsKit.EntityFrameworkCore
b.Property(x => x.Content).HasMaxLength(PageConsts.MaxContentLength); b.Property(x => x.Content).HasMaxLength(PageConsts.MaxContentLength);
b.HasIndex(x => new { x.TenantId, Url = x.Slug }); b.HasIndex(x => new { x.TenantId, Url = x.Slug });
b.ApplyObjectExtensionMappings();
}); });
} }
else else
@ -181,6 +195,8 @@ namespace Volo.CmsKit.EntityFrameworkCore
b.Property(p => p.Name).IsRequired().HasMaxLength(BlogConsts.MaxNameLength); b.Property(p => p.Name).IsRequired().HasMaxLength(BlogConsts.MaxNameLength);
b.Property(p => p.Slug).IsRequired().HasMaxLength(BlogConsts.MaxSlugLength); b.Property(p => p.Slug).IsRequired().HasMaxLength(BlogConsts.MaxSlugLength);
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<BlogPost>(b => builder.Entity<BlogPost>(b =>
@ -194,8 +210,10 @@ namespace Volo.CmsKit.EntityFrameworkCore
b.Property(p => p.Slug).IsRequired().HasMaxLength(BlogPostConsts.MaxSlugLength); b.Property(p => p.Slug).IsRequired().HasMaxLength(BlogPostConsts.MaxSlugLength);
b.Property(p => p.ShortDescription).HasMaxLength(BlogPostConsts.MaxShortDescriptionLength); b.Property(p => p.ShortDescription).HasMaxLength(BlogPostConsts.MaxShortDescriptionLength);
b.Property(p => p.Content).HasMaxLength(BlogPostConsts.MaxContentLength); b.Property(p => p.Content).HasMaxLength(BlogPostConsts.MaxContentLength);
b.HasIndex(x => new { x.Slug, x.BlogId }); b.HasIndex(x => new { x.Slug, x.BlogId });
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<BlogFeature>(b => builder.Entity<BlogFeature>(b =>
@ -205,6 +223,8 @@ namespace Volo.CmsKit.EntityFrameworkCore
b.ConfigureByConvention(); b.ConfigureByConvention();
b.Property(p => p.FeatureName).IsRequired().HasMaxLength(BlogFeatureConsts.MaxFeatureNameLenth); b.Property(p => p.FeatureName).IsRequired().HasMaxLength(BlogFeatureConsts.MaxFeatureNameLenth);
b.ApplyObjectExtensionMappings();
}); });
} }
else else
@ -226,12 +246,16 @@ namespace Volo.CmsKit.EntityFrameworkCore
b.Property(x => x.Name).IsRequired().HasMaxLength(MediaDescriptorConsts.MaxNameLength); b.Property(x => x.Name).IsRequired().HasMaxLength(MediaDescriptorConsts.MaxNameLength);
b.Property(x => x.MimeType).IsRequired().HasMaxLength(MediaDescriptorConsts.MaxMimeTypeLength); b.Property(x => x.MimeType).IsRequired().HasMaxLength(MediaDescriptorConsts.MaxMimeTypeLength);
b.Property(x => x.Size).HasMaxLength(MediaDescriptorConsts.MaxSizeLength); b.Property(x => x.Size).HasMaxLength(MediaDescriptorConsts.MaxSizeLength);
b.ApplyObjectExtensionMappings();
}); });
} }
else else
{ {
builder.Ignore<MediaDescriptor>(); builder.Ignore<MediaDescriptor>();
} }
builder.TryConfigureObjectExtensions<CmsKitDbContext>();
} }
} }
} }

8
modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/EntityFrameworkCore/DocsDbContextModelBuilderExtensions.cs

@ -40,6 +40,8 @@ namespace Volo.Docs.EntityFrameworkCore
b.Property(x => x.NavigationDocumentName).IsRequired().HasMaxLength(ProjectConsts.MaxNavigationDocumentNameLength); b.Property(x => x.NavigationDocumentName).IsRequired().HasMaxLength(ProjectConsts.MaxNavigationDocumentNameLength);
b.Property(x => x.ParametersDocumentName).IsRequired().HasMaxLength(ProjectConsts.MaxParametersDocumentNameLength); b.Property(x => x.ParametersDocumentName).IsRequired().HasMaxLength(ProjectConsts.MaxParametersDocumentNameLength);
b.Property(x => x.LatestVersionBranchName).HasMaxLength(ProjectConsts.MaxLatestVersionBranchNameLength); b.Property(x => x.LatestVersionBranchName).HasMaxLength(ProjectConsts.MaxLatestVersionBranchNameLength);
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<Document>(b => builder.Entity<Document>(b =>
@ -62,6 +64,8 @@ namespace Volo.Docs.EntityFrameworkCore
b.HasMany(x => x.Contributors).WithOne() b.HasMany(x => x.Contributors).WithOne()
.HasForeignKey(x => new { x.DocumentId }) .HasForeignKey(x => new { x.DocumentId })
.IsRequired(); .IsRequired();
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<DocumentContributor>(b => builder.Entity<DocumentContributor>(b =>
@ -71,7 +75,11 @@ namespace Volo.Docs.EntityFrameworkCore
b.ConfigureByConvention(); b.ConfigureByConvention();
b.HasKey(x => new { x.DocumentId, x.Username }); b.HasKey(x => new { x.DocumentId, x.Username });
b.ApplyObjectExtensionMappings();
}); });
builder.TryConfigureObjectExtensions<DocsDbContext>();
} }
} }
} }

4
modules/feature-management/src/Volo.Abp.FeatureManagement.EntityFrameworkCore/Volo/Abp/FeatureManagement/EntityFrameworkCore/FeatureManagementDbContextModelCreatingExtensions.cs

@ -36,7 +36,11 @@ namespace Volo.Abp.FeatureManagement.EntityFrameworkCore
b.Property(x => x.ProviderKey).HasMaxLength(FeatureValueConsts.MaxProviderKeyLength); b.Property(x => x.ProviderKey).HasMaxLength(FeatureValueConsts.MaxProviderKeyLength);
b.HasIndex(x => new { x.Name, x.ProviderName, x.ProviderKey }); b.HasIndex(x => new { x.Name, x.ProviderName, x.ProviderKey });
b.ApplyObjectExtensionMappings();
}); });
builder.TryConfigureObjectExtensions<FeatureManagementDbContext>();
} }
} }
} }

28
modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityDbContextModelBuilderExtensions.cs

@ -60,6 +60,8 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
b.HasIndex(u => u.NormalizedEmail); b.HasIndex(u => u.NormalizedEmail);
b.HasIndex(u => u.UserName); b.HasIndex(u => u.UserName);
b.HasIndex(u => u.Email); b.HasIndex(u => u.Email);
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<IdentityUserClaim>(b => builder.Entity<IdentityUserClaim>(b =>
@ -74,6 +76,8 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
b.Property(uc => uc.ClaimValue).HasMaxLength(IdentityUserClaimConsts.MaxClaimValueLength); b.Property(uc => uc.ClaimValue).HasMaxLength(IdentityUserClaimConsts.MaxClaimValueLength);
b.HasIndex(uc => uc.UserId); b.HasIndex(uc => uc.UserId);
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<IdentityUserRole>(b => builder.Entity<IdentityUserRole>(b =>
@ -88,6 +92,8 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
b.HasOne<IdentityUser>().WithMany(u => u.Roles).HasForeignKey(ur => ur.UserId).IsRequired(); b.HasOne<IdentityUser>().WithMany(u => u.Roles).HasForeignKey(ur => ur.UserId).IsRequired();
b.HasIndex(ur => new {ur.RoleId, ur.UserId}); b.HasIndex(ur => new {ur.RoleId, ur.UserId});
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<IdentityUserLogin>(b => builder.Entity<IdentityUserLogin>(b =>
@ -106,6 +112,8 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
.HasMaxLength(IdentityUserLoginConsts.MaxProviderDisplayNameLength); .HasMaxLength(IdentityUserLoginConsts.MaxProviderDisplayNameLength);
b.HasIndex(l => new {l.LoginProvider, l.ProviderKey}); b.HasIndex(l => new {l.LoginProvider, l.ProviderKey});
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<IdentityUserToken>(b => builder.Entity<IdentityUserToken>(b =>
@ -119,6 +127,8 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
b.Property(ul => ul.LoginProvider).HasMaxLength(IdentityUserTokenConsts.MaxLoginProviderLength) b.Property(ul => ul.LoginProvider).HasMaxLength(IdentityUserTokenConsts.MaxLoginProviderLength)
.IsRequired(); .IsRequired();
b.Property(ul => ul.Name).HasMaxLength(IdentityUserTokenConsts.MaxNameLength).IsRequired(); b.Property(ul => ul.Name).HasMaxLength(IdentityUserTokenConsts.MaxNameLength).IsRequired();
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<IdentityRole>(b => builder.Entity<IdentityRole>(b =>
@ -136,6 +146,8 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
b.HasMany(r => r.Claims).WithOne().HasForeignKey(rc => rc.RoleId).IsRequired(); b.HasMany(r => r.Claims).WithOne().HasForeignKey(rc => rc.RoleId).IsRequired();
b.HasIndex(r => r.NormalizedName); b.HasIndex(r => r.NormalizedName);
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<IdentityRoleClaim>(b => builder.Entity<IdentityRoleClaim>(b =>
@ -150,6 +162,8 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
b.Property(uc => uc.ClaimValue).HasMaxLength(IdentityRoleClaimConsts.MaxClaimValueLength); b.Property(uc => uc.ClaimValue).HasMaxLength(IdentityRoleClaimConsts.MaxClaimValueLength);
b.HasIndex(uc => uc.RoleId); b.HasIndex(uc => uc.RoleId);
b.ApplyObjectExtensionMappings();
}); });
if (builder.IsHostDatabase()) if (builder.IsHostDatabase())
@ -165,6 +179,8 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
b.Property(uc => uc.Regex).HasMaxLength(IdentityClaimTypeConsts.MaxRegexLength); b.Property(uc => uc.Regex).HasMaxLength(IdentityClaimTypeConsts.MaxRegexLength);
b.Property(uc => uc.RegexDescription).HasMaxLength(IdentityClaimTypeConsts.MaxRegexDescriptionLength); b.Property(uc => uc.RegexDescription).HasMaxLength(IdentityClaimTypeConsts.MaxRegexDescriptionLength);
b.Property(uc => uc.Description).HasMaxLength(IdentityClaimTypeConsts.MaxDescriptionLength); b.Property(uc => uc.Description).HasMaxLength(IdentityClaimTypeConsts.MaxDescriptionLength);
b.ApplyObjectExtensionMappings();
}); });
} }
@ -183,6 +199,8 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
b.HasMany(ou => ou.Roles).WithOne().HasForeignKey(our => our.OrganizationUnitId).IsRequired(); b.HasMany(ou => ou.Roles).WithOne().HasForeignKey(our => our.OrganizationUnitId).IsRequired();
b.HasIndex(ou => ou.Code); b.HasIndex(ou => ou.Code);
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<OrganizationUnitRole>(b => builder.Entity<OrganizationUnitRole>(b =>
@ -196,6 +214,8 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
b.HasOne<IdentityRole>().WithMany().HasForeignKey(ou => ou.RoleId).IsRequired(); b.HasOne<IdentityRole>().WithMany().HasForeignKey(ou => ou.RoleId).IsRequired();
b.HasIndex(ou => new {ou.RoleId, ou.OrganizationUnitId}); b.HasIndex(ou => new {ou.RoleId, ou.OrganizationUnitId});
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<IdentityUserOrganizationUnit>(b => builder.Entity<IdentityUserOrganizationUnit>(b =>
@ -209,6 +229,8 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
b.HasOne<OrganizationUnit>().WithMany().HasForeignKey(ou => ou.OrganizationUnitId).IsRequired(); b.HasOne<OrganizationUnit>().WithMany().HasForeignKey(ou => ou.OrganizationUnitId).IsRequired();
b.HasIndex(ou => new {ou.UserId, ou.OrganizationUnitId}); b.HasIndex(ou => new {ou.UserId, ou.OrganizationUnitId});
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<IdentitySecurityLog>(b => builder.Entity<IdentitySecurityLog>(b =>
@ -234,6 +256,8 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
b.HasIndex(x => new { x.TenantId, x.Identity }); b.HasIndex(x => new { x.TenantId, x.Identity });
b.HasIndex(x => new { x.TenantId, x.Action }); b.HasIndex(x => new { x.TenantId, x.Action });
b.HasIndex(x => new { x.TenantId, x.UserId }); b.HasIndex(x => new { x.TenantId, x.UserId });
b.ApplyObjectExtensionMappings();
}); });
if (builder.IsHostDatabase()) if (builder.IsHostDatabase())
@ -251,8 +275,12 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
LinkedUserId = x.TargetUserId, LinkedUserId = x.TargetUserId,
LinkedTenantId = x.TargetTenantId LinkedTenantId = x.TargetTenantId
}).IsUnique(); }).IsUnique();
b.ApplyObjectExtensionMappings();
}); });
} }
builder.TryConfigureObjectExtensions<IdentityDbContext>();
} }
} }
} }

48
modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerDbContextModelCreatingExtensions.cs

@ -63,6 +63,8 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore
b.HasMany(x => x.Properties).WithOne().HasForeignKey(x => x.ClientId).IsRequired(); b.HasMany(x => x.Properties).WithOne().HasForeignKey(x => x.ClientId).IsRequired();
b.HasIndex(x => x.ClientId); b.HasIndex(x => x.ClientId);
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<ClientGrantType>(b => builder.Entity<ClientGrantType>(b =>
@ -74,6 +76,8 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore
b.HasKey(x => new {x.ClientId, x.GrantType}); b.HasKey(x => new {x.ClientId, x.GrantType});
b.Property(x => x.GrantType).HasMaxLength(ClientGrantTypeConsts.GrantTypeMaxLength).IsRequired(); b.Property(x => x.GrantType).HasMaxLength(ClientGrantTypeConsts.GrantTypeMaxLength).IsRequired();
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<ClientRedirectUri>(b => builder.Entity<ClientRedirectUri>(b =>
@ -90,6 +94,8 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore
} }
b.Property(x => x.RedirectUri).HasMaxLength(ClientRedirectUriConsts.RedirectUriMaxLengthValue).IsRequired(); b.Property(x => x.RedirectUri).HasMaxLength(ClientRedirectUriConsts.RedirectUriMaxLengthValue).IsRequired();
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<ClientPostLogoutRedirectUri>(b => builder.Entity<ClientPostLogoutRedirectUri>(b =>
@ -108,6 +114,8 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore
b.Property(x => x.PostLogoutRedirectUri) b.Property(x => x.PostLogoutRedirectUri)
.HasMaxLength(ClientPostLogoutRedirectUriConsts.PostLogoutRedirectUriMaxLengthValue) .HasMaxLength(ClientPostLogoutRedirectUriConsts.PostLogoutRedirectUriMaxLengthValue)
.IsRequired(); .IsRequired();
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<ClientScope>(b => builder.Entity<ClientScope>(b =>
@ -119,6 +127,8 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore
b.HasKey(x => new {x.ClientId, x.Scope}); b.HasKey(x => new {x.ClientId, x.Scope});
b.Property(x => x.Scope).HasMaxLength(ClientScopeConsts.ScopeMaxLength).IsRequired(); b.Property(x => x.Scope).HasMaxLength(ClientScopeConsts.ScopeMaxLength).IsRequired();
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<ClientSecret>(b => builder.Entity<ClientSecret>(b =>
@ -136,6 +146,8 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore
} }
b.Property(x => x.Value).HasMaxLength(ClientSecretConsts.ValueMaxLength).IsRequired(); b.Property(x => x.Value).HasMaxLength(ClientSecretConsts.ValueMaxLength).IsRequired();
b.Property(x => x.Description).HasMaxLength(ClientSecretConsts.DescriptionMaxLength); b.Property(x => x.Description).HasMaxLength(ClientSecretConsts.DescriptionMaxLength);
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<ClientClaim>(b => builder.Entity<ClientClaim>(b =>
@ -148,6 +160,8 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore
b.Property(x => x.Type).HasMaxLength(ClientClaimConsts.TypeMaxLength).IsRequired(); b.Property(x => x.Type).HasMaxLength(ClientClaimConsts.TypeMaxLength).IsRequired();
b.Property(x => x.Value).HasMaxLength(ClientClaimConsts.ValueMaxLength).IsRequired(); b.Property(x => x.Value).HasMaxLength(ClientClaimConsts.ValueMaxLength).IsRequired();
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<ClientIdPRestriction>(b => builder.Entity<ClientIdPRestriction>(b =>
@ -159,6 +173,8 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore
b.HasKey(x => new {x.ClientId, x.Provider}); b.HasKey(x => new {x.ClientId, x.Provider});
b.Property(x => x.Provider).HasMaxLength(ClientIdPRestrictionConsts.ProviderMaxLength).IsRequired(); b.Property(x => x.Provider).HasMaxLength(ClientIdPRestrictionConsts.ProviderMaxLength).IsRequired();
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<ClientCorsOrigin>(b => builder.Entity<ClientCorsOrigin>(b =>
@ -170,6 +186,8 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore
b.HasKey(x => new {x.ClientId, x.Origin}); b.HasKey(x => new {x.ClientId, x.Origin});
b.Property(x => x.Origin).HasMaxLength(ClientCorsOriginConsts.OriginMaxLength).IsRequired(); b.Property(x => x.Origin).HasMaxLength(ClientCorsOriginConsts.OriginMaxLength).IsRequired();
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<ClientProperty>(b => builder.Entity<ClientProperty>(b =>
@ -186,6 +204,8 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore
ClientPropertyConsts.ValueMaxLength = 300; ClientPropertyConsts.ValueMaxLength = 300;
} }
b.Property(x => x.Value).HasMaxLength(ClientPropertyConsts.ValueMaxLength).IsRequired(); b.Property(x => x.Value).HasMaxLength(ClientPropertyConsts.ValueMaxLength).IsRequired();
b.ApplyObjectExtensionMappings();
}); });
#endregion #endregion
@ -204,6 +224,8 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore
b.HasMany(x => x.UserClaims).WithOne().HasForeignKey(x => x.IdentityResourceId).IsRequired(); b.HasMany(x => x.UserClaims).WithOne().HasForeignKey(x => x.IdentityResourceId).IsRequired();
b.HasMany(x => x.Properties).WithOne().HasForeignKey(x => x.IdentityResourceId).IsRequired(); b.HasMany(x => x.Properties).WithOne().HasForeignKey(x => x.IdentityResourceId).IsRequired();
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<IdentityResourceClaim>(b => builder.Entity<IdentityResourceClaim>(b =>
@ -215,6 +237,8 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore
b.HasKey(x => new {x.IdentityResourceId, x.Type}); b.HasKey(x => new {x.IdentityResourceId, x.Type});
b.Property(x => x.Type).HasMaxLength(UserClaimConsts.TypeMaxLength).IsRequired(); b.Property(x => x.Type).HasMaxLength(UserClaimConsts.TypeMaxLength).IsRequired();
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<IdentityResourceProperty>(b => builder.Entity<IdentityResourceProperty>(b =>
@ -231,6 +255,8 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore
IdentityResourcePropertyConsts.ValueMaxLength = 300; IdentityResourcePropertyConsts.ValueMaxLength = 300;
} }
b.Property(x => x.Value).HasMaxLength(IdentityResourcePropertyConsts.ValueMaxLength).IsRequired(); b.Property(x => x.Value).HasMaxLength(IdentityResourcePropertyConsts.ValueMaxLength).IsRequired();
b.ApplyObjectExtensionMappings();
}); });
#endregion #endregion
@ -252,6 +278,8 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore
b.HasMany(x => x.Scopes).WithOne().HasForeignKey(x => x.ApiResourceId).IsRequired(); b.HasMany(x => x.Scopes).WithOne().HasForeignKey(x => x.ApiResourceId).IsRequired();
b.HasMany(x => x.UserClaims).WithOne().HasForeignKey(x => x.ApiResourceId).IsRequired(); b.HasMany(x => x.UserClaims).WithOne().HasForeignKey(x => x.ApiResourceId).IsRequired();
b.HasMany(x => x.Properties).WithOne().HasForeignKey(x => x.ApiResourceId).IsRequired(); b.HasMany(x => x.Properties).WithOne().HasForeignKey(x => x.ApiResourceId).IsRequired();
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<ApiResourceSecret>(b => builder.Entity<ApiResourceSecret>(b =>
@ -271,6 +299,8 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore
b.Property(x => x.Value).HasMaxLength(ApiResourceSecretConsts.ValueMaxLength).IsRequired(); b.Property(x => x.Value).HasMaxLength(ApiResourceSecretConsts.ValueMaxLength).IsRequired();
b.Property(x => x.Description).HasMaxLength(ApiResourceSecretConsts.DescriptionMaxLength); b.Property(x => x.Description).HasMaxLength(ApiResourceSecretConsts.DescriptionMaxLength);
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<ApiResourceClaim>(b => builder.Entity<ApiResourceClaim>(b =>
@ -282,6 +312,8 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore
b.HasKey(x => new {x.ApiResourceId, x.Type}); b.HasKey(x => new {x.ApiResourceId, x.Type});
b.Property(x => x.Type).HasMaxLength(UserClaimConsts.TypeMaxLength).IsRequired(); b.Property(x => x.Type).HasMaxLength(UserClaimConsts.TypeMaxLength).IsRequired();
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<ApiResourceScope>(b => builder.Entity<ApiResourceScope>(b =>
@ -293,6 +325,8 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore
b.HasKey(x => new {x.ApiResourceId, x.Scope}); b.HasKey(x => new {x.ApiResourceId, x.Scope});
b.Property(x => x.Scope).HasMaxLength(ApiResourceScopeConsts.ScopeMaxLength).IsRequired(); b.Property(x => x.Scope).HasMaxLength(ApiResourceScopeConsts.ScopeMaxLength).IsRequired();
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<ApiResourceProperty>(b => builder.Entity<ApiResourceProperty>(b =>
@ -309,6 +343,8 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore
ApiResourcePropertyConsts.ValueMaxLength = 300; ApiResourcePropertyConsts.ValueMaxLength = 300;
} }
b.Property(x => x.Value).HasMaxLength(ApiResourcePropertyConsts.ValueMaxLength).IsRequired(); b.Property(x => x.Value).HasMaxLength(ApiResourcePropertyConsts.ValueMaxLength).IsRequired();
b.ApplyObjectExtensionMappings();
}); });
#endregion #endregion
@ -327,6 +363,8 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore
b.HasMany(x => x.UserClaims).WithOne().HasForeignKey(x => x.ApiScopeId).IsRequired(); b.HasMany(x => x.UserClaims).WithOne().HasForeignKey(x => x.ApiScopeId).IsRequired();
b.HasMany(x => x.Properties).WithOne().HasForeignKey(x => x.ApiScopeId).IsRequired(); b.HasMany(x => x.Properties).WithOne().HasForeignKey(x => x.ApiScopeId).IsRequired();
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<ApiScopeClaim>(b => builder.Entity<ApiScopeClaim>(b =>
@ -338,6 +376,8 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore
b.HasKey(x => new {x.ApiScopeId, x.Type}); b.HasKey(x => new {x.ApiScopeId, x.Type});
b.Property(x => x.Type).HasMaxLength(UserClaimConsts.TypeMaxLength).IsRequired(); b.Property(x => x.Type).HasMaxLength(UserClaimConsts.TypeMaxLength).IsRequired();
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<ApiScopeProperty>(b => builder.Entity<ApiScopeProperty>(b =>
@ -354,6 +394,8 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore
ApiScopePropertyConsts.ValueMaxLength = 300; ApiScopePropertyConsts.ValueMaxLength = 300;
} }
b.Property(x => x.Value).HasMaxLength(ApiScopePropertyConsts.ValueMaxLength).IsRequired(); b.Property(x => x.Value).HasMaxLength(ApiScopePropertyConsts.ValueMaxLength).IsRequired();
b.ApplyObjectExtensionMappings();
}); });
#endregion #endregion
@ -386,6 +428,8 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore
b.HasIndex(x => new {x.SubjectId, x.ClientId, x.Type}); b.HasIndex(x => new {x.SubjectId, x.ClientId, x.Type});
b.HasIndex(x => new {x.SubjectId, x.SessionId, x.Type}); b.HasIndex(x => new {x.SubjectId, x.SessionId, x.Type});
b.HasIndex(x => x.Expiration); b.HasIndex(x => x.Expiration);
b.ApplyObjectExtensionMappings();
}); });
#endregion #endregion
@ -416,9 +460,13 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore
b.HasIndex(x => new {x.UserCode}); b.HasIndex(x => new {x.UserCode});
b.HasIndex(x => x.DeviceCode).IsUnique(); b.HasIndex(x => x.DeviceCode).IsUnique();
b.HasIndex(x => x.Expiration); b.HasIndex(x => x.Expiration);
b.ApplyObjectExtensionMappings();
}); });
#endregion #endregion
builder.TryConfigureObjectExtensions<IdentityServerDbContext>();
} }
private static bool IsDatabaseProvider( private static bool IsDatabaseProvider(

6
modules/permission-management/src/Volo.Abp.PermissionManagement.EntityFrameworkCore/Volo/Abp/PermissionManagement/EntityFrameworkCore/AbpPermissionManagementDbContextModelBuilderExtensions.cs

@ -31,7 +31,11 @@ namespace Volo.Abp.PermissionManagement.EntityFrameworkCore
b.Property(x => x.ProviderKey).HasMaxLength(PermissionGrantConsts.MaxProviderKeyLength).IsRequired(); b.Property(x => x.ProviderKey).HasMaxLength(PermissionGrantConsts.MaxProviderKeyLength).IsRequired();
b.HasIndex(x => new {x.Name, x.ProviderName, x.ProviderKey}); b.HasIndex(x => new {x.Name, x.ProviderName, x.ProviderKey});
b.ApplyObjectExtensionMappings();
}); });
builder.TryConfigureObjectExtensions<PermissionManagementDbContext>();
} }
} }
} }

4
modules/setting-management/src/Volo.Abp.SettingManagement.EntityFrameworkCore/Volo/Abp/SettingManagement/EntityFrameworkCore/SettingManagementDbContextModelBuilderExtensions.cs

@ -54,7 +54,11 @@ namespace Volo.Abp.SettingManagement.EntityFrameworkCore
b.Property(x => x.ProviderKey).HasMaxLength(SettingConsts.MaxProviderKeyLength); b.Property(x => x.ProviderKey).HasMaxLength(SettingConsts.MaxProviderKeyLength);
b.HasIndex(x => new {x.Name, x.ProviderName, x.ProviderKey}); b.HasIndex(x => new {x.Name, x.ProviderName, x.ProviderKey});
b.ApplyObjectExtensionMappings();
}); });
builder.TryConfigureObjectExtensions<SettingManagementDbContext>();
} }
} }
} }

6
modules/tenant-management/src/Volo.Abp.TenantManagement.EntityFrameworkCore/Volo/Abp/TenantManagement/EntityFrameworkCore/AbpTenantManagementDbContextModelCreatingExtensions.cs

@ -36,6 +36,8 @@ namespace Volo.Abp.TenantManagement.EntityFrameworkCore
b.HasMany(u => u.ConnectionStrings).WithOne().HasForeignKey(uc => uc.TenantId).IsRequired(); b.HasMany(u => u.ConnectionStrings).WithOne().HasForeignKey(uc => uc.TenantId).IsRequired();
b.HasIndex(u => u.Name); b.HasIndex(u => u.Name);
b.ApplyObjectExtensionMappings();
}); });
builder.Entity<TenantConnectionString>(b => builder.Entity<TenantConnectionString>(b =>
@ -48,7 +50,11 @@ namespace Volo.Abp.TenantManagement.EntityFrameworkCore
b.Property(cs => cs.Name).IsRequired().HasMaxLength(TenantConnectionStringConsts.MaxNameLength); b.Property(cs => cs.Name).IsRequired().HasMaxLength(TenantConnectionStringConsts.MaxNameLength);
b.Property(cs => cs.Value).IsRequired().HasMaxLength(TenantConnectionStringConsts.MaxValueLength); b.Property(cs => cs.Value).IsRequired().HasMaxLength(TenantConnectionStringConsts.MaxValueLength);
b.ApplyObjectExtensionMappings();
}); });
builder.TryConfigureObjectExtensions<TenantManagementDbContext>();
} }
} }
} }

Loading…
Cancel
Save