Browse Source

Apply Entity Extension System for samples

Resolve #3361
pull/3366/head
maliming 6 years ago
parent
commit
283da6783b
  1. 16
      samples/BookStore-Angular-MongoDb/aspnet-core/src/Acme.BookStore.Domain/Users/AppUser.cs
  2. 16
      samples/BookStore-Modular/application/src/Acme.BookStore.Domain/Users/AppUser.cs
  3. 7
      samples/BookStore-Modular/application/src/Acme.BookStore.EntityFrameworkCore.DbMigrations/EntityFrameworkCore/BookStoreMigrationsDbContext.cs
  4. 2
      samples/BookStore-Modular/application/src/Acme.BookStore.EntityFrameworkCore.DbMigrations/EntityFrameworkCore/BookStoreMigrationsDbContextFactory.cs
  5. 8
      samples/BookStore-Modular/application/src/Acme.BookStore.EntityFrameworkCore/EntityFrameworkCore/BookStoreDbContext.cs
  6. 8
      samples/BookStore-Modular/application/src/Acme.BookStore.EntityFrameworkCore/EntityFrameworkCore/BookStoreDbContextModelCreatingExtensions.cs
  7. 33
      samples/BookStore-Modular/application/src/Acme.BookStore.EntityFrameworkCore/EntityFrameworkCore/BookStoreEntityExtensions.cs
  8. 5
      samples/BookStore-Modular/application/src/Acme.BookStore.EntityFrameworkCore/EntityFrameworkCore/BookStoreEntityFrameworkCoreModule.cs
  9. 32
      samples/BookStore-Modular/modules/book-management/src/Acme.BookStore.BookManagement.EntityFrameworkCore/EntityFrameworkCore/BookManagementEntityExtensions.cs
  10. 5
      samples/BookStore-Modular/modules/book-management/src/Acme.BookStore.BookManagement.EntityFrameworkCore/EntityFrameworkCore/BookManagementEntityFrameworkCoreModule.cs
  11. 16
      samples/BookStore/src/Acme.BookStore.Domain/Users/AppUser.cs
  12. 7
      samples/BookStore/src/Acme.BookStore.EntityFrameworkCore.DbMigrations/EntityFrameworkCore/BookStoreMigrationsDbContext.cs
  13. 2
      samples/BookStore/src/Acme.BookStore.EntityFrameworkCore.DbMigrations/EntityFrameworkCore/BookStoreMigrationsDbContextFactory.cs
  14. 8
      samples/BookStore/src/Acme.BookStore.EntityFrameworkCore/EntityFrameworkCore/BookStoreDbContext.cs
  15. 8
      samples/BookStore/src/Acme.BookStore.EntityFrameworkCore/EntityFrameworkCore/BookStoreDbContextModelCreatingExtensions.cs
  16. 33
      samples/BookStore/src/Acme.BookStore.EntityFrameworkCore/EntityFrameworkCore/BookStoreEntityExtensions.cs
  17. 5
      samples/BookStore/src/Acme.BookStore.EntityFrameworkCore/EntityFrameworkCore/BookStoreEntityFrameworkCoreModule.cs
  18. 16
      samples/DashboardDemo/src/DashboardDemo.Domain/Users/AppUser.cs
  19. 7
      samples/DashboardDemo/src/DashboardDemo.EntityFrameworkCore.DbMigrations/EntityFrameworkCore/DashboardDemoMigrationsDbContext.cs
  20. 2
      samples/DashboardDemo/src/DashboardDemo.EntityFrameworkCore.DbMigrations/EntityFrameworkCore/DashboardDemoMigrationsDbContextFactory.cs
  21. 8
      samples/DashboardDemo/src/DashboardDemo.EntityFrameworkCore/EntityFrameworkCore/DashboardDemoDbContext.cs
  22. 8
      samples/DashboardDemo/src/DashboardDemo.EntityFrameworkCore/EntityFrameworkCore/DashboardDemoDbContextModelCreatingExtensions.cs
  23. 33
      samples/DashboardDemo/src/DashboardDemo.EntityFrameworkCore/EntityFrameworkCore/DashboardDemoEntityExtensions.cs
  24. 5
      samples/DashboardDemo/src/DashboardDemo.EntityFrameworkCore/EntityFrameworkCore/DashboardDemoEntityFrameworkCoreModule.cs
  25. 16
      samples/EfCoreMigrationDemo/src/Acme.BookStore.Domain/Users/AppUser.cs
  26. 13
      samples/EfCoreMigrationDemo/src/Acme.BookStore.EntityFrameworkCore.DbMigrations/EntityFrameworkCore/BookStoreMigrationsDbContext.cs
  27. 2
      samples/EfCoreMigrationDemo/src/Acme.BookStore.EntityFrameworkCore.DbMigrations/EntityFrameworkCore/BookStoreMigrationsDbContextFactory.cs
  28. 8
      samples/EfCoreMigrationDemo/src/Acme.BookStore.EntityFrameworkCore/EntityFrameworkCore/BookStoreDbContext.cs
  29. 19
      samples/EfCoreMigrationDemo/src/Acme.BookStore.EntityFrameworkCore/EntityFrameworkCore/BookStoreDbContextModelCreatingExtensions.cs
  30. 40
      samples/EfCoreMigrationDemo/src/Acme.BookStore.EntityFrameworkCore/EntityFrameworkCore/BookStoreEntityExtensions.cs
  31. 5
      samples/EfCoreMigrationDemo/src/Acme.BookStore.EntityFrameworkCore/EntityFrameworkCore/BookStoreEntityFrameworkCoreModule.cs

16
samples/BookStore-Angular-MongoDb/aspnet-core/src/Acme.BookStore.Domain/Users/AppUser.cs

@ -41,9 +41,19 @@ namespace Acme.BookStore.Users
#endregion
/* Add your own properties here. Example:
*
* public virtual string MyProperty { get; set; }
*/
*
* public string MyProperty { get; set; }
*
* If you add a property and using the EF Core, remember these;
*
* 1. update BookStoreDbContext.OnModelCreating
* to configure the mapping for your new property
* 2. Update BookStoreEntityExtensions to extend the IdentityUser entity
* and add your new property to the migration.
* 3. Use the Add-Migration to add a new database migration.
* 4. Run the .DbMigrator project (or use the Update-Database command) to apply
* schema change to the database.
*/
private AppUser()
{

16
samples/BookStore-Modular/application/src/Acme.BookStore.Domain/Users/AppUser.cs

@ -41,9 +41,19 @@ namespace Acme.BookStore.Users
#endregion
/* Add your own properties here. Example:
*
* public virtual string MyProperty { get; set; }
*/
*
* public string MyProperty { get; set; }
*
* If you add a property and using the EF Core, remember these;
*
* 1. update BookStoreDbContext.OnModelCreating
* to configure the mapping for your new property
* 2. Update BookStoreEntityExtensions to extend the IdentityUser entity
* and add your new property to the migration.
* 3. Use the Add-Migration to add a new database migration.
* 4. Run the .DbMigrator project (or use the Update-Database command) to apply
* schema change to the database.
*/
private AppUser()
{

7
samples/BookStore-Modular/application/src/Acme.BookStore.EntityFrameworkCore.DbMigrations/EntityFrameworkCore/BookStoreMigrationsDbContext.cs

@ -42,13 +42,6 @@ namespace Acme.BookStore.EntityFrameworkCore
builder.ConfigureTenantManagement();
builder.ConfigureBookManagement();
/* Configure customizations for entities from the modules included */
builder.Entity<IdentityUser>(b =>
{
b.ConfigureCustomUserProperties();
});
/* Configure your own tables/entities inside the ConfigureBookStore method */
builder.ConfigureBookStore();

2
samples/BookStore-Modular/application/src/Acme.BookStore.EntityFrameworkCore.DbMigrations/EntityFrameworkCore/BookStoreMigrationsDbContextFactory.cs

@ -11,6 +11,8 @@ namespace Acme.BookStore.EntityFrameworkCore
{
public BookStoreMigrationsDbContext CreateDbContext(string[] args)
{
BookStoreEntityExtensions.Configure();
var configuration = BuildConfiguration();
var builder = new DbContextOptionsBuilder<BookStoreMigrationsDbContext>()

8
samples/BookStore-Modular/application/src/Acme.BookStore.EntityFrameworkCore/EntityFrameworkCore/BookStoreDbContext.cs

@ -3,6 +3,7 @@ using Acme.BookStore.Users;
using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.Modeling;
using Volo.Abp.Identity;
using Volo.Abp.Users.EntityFrameworkCore;
namespace Acme.BookStore.EntityFrameworkCore
@ -39,12 +40,13 @@ namespace Acme.BookStore.EntityFrameworkCore
builder.Entity<AppUser>(b =>
{
b.ToTable("AbpUsers"); //Sharing the same table "AbpUsers" with the IdentityUser
b.ToTable(AbpIdentityDbProperties.DbTablePrefix + "Users"); //Sharing the same table "AbpUsers" with the IdentityUser
b.ConfigureByConvention();
b.ConfigureAbpUser();
//Moved customization to a method so we can share it with the BookStoreMigrationsDbContext class
b.ConfigureCustomUserProperties();
/* Configure mappings for your additional properties
* Also see the BookStoreEntityExtensions class
*/
});
/* Configure your own tables/entities inside the ConfigureBookStore method */

8
samples/BookStore-Modular/application/src/Acme.BookStore.EntityFrameworkCore/EntityFrameworkCore/BookStoreDbContextModelCreatingExtensions.cs

@ -1,7 +1,5 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Volo.Abp;
using Volo.Abp.Users;
namespace Acme.BookStore.EntityFrameworkCore
{
@ -20,11 +18,5 @@ namespace Acme.BookStore.EntityFrameworkCore
// //...
//});
}
public static void ConfigureCustomUserProperties<TUser>(this EntityTypeBuilder<TUser> b)
where TUser: class, IUser
{
//b.Property<string>(nameof(AppUser.MyProperty))...
}
}
}

33
samples/BookStore-Modular/application/src/Acme.BookStore.EntityFrameworkCore/EntityFrameworkCore/BookStoreEntityExtensions.cs

@ -0,0 +1,33 @@
using Volo.Abp.EntityFrameworkCore.Extensions;
using Volo.Abp.Identity;
using Volo.Abp.Threading;
namespace Acme.BookStore.EntityFrameworkCore
{
public static class BookStoreEntityExtensions
{
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();
public static void Configure()
{
OneTimeRunner.Run(() =>
{
/* You can configure entity extension properties for the
* entities defined in the used modules.
*
* Example:
*
* EntityExtensionManager.AddProperty<IdentityUser, string>(
* "MyProperty",
* b =>
* {
* b.HasMaxLength(128);
* });
*
* See the documentation for more:
* https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Extending-Entities
*/
});
}
}
}

5
samples/BookStore-Modular/application/src/Acme.BookStore.EntityFrameworkCore/EntityFrameworkCore/BookStoreEntityFrameworkCoreModule.cs

@ -29,6 +29,11 @@ namespace Acme.BookStore.EntityFrameworkCore
)]
public class BookStoreEntityFrameworkCoreModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
BookStoreEntityExtensions.Configure();
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddAbpDbContext<BookStoreDbContext>(options =>

32
samples/BookStore-Modular/modules/book-management/src/Acme.BookStore.BookManagement.EntityFrameworkCore/EntityFrameworkCore/BookManagementEntityExtensions.cs

@ -0,0 +1,32 @@
using Volo.Abp.EntityFrameworkCore.Extensions;
using Volo.Abp.Threading;
namespace Acme.BookStore.BookManagement.EntityFrameworkCore
{
public static class BookManagementEntityExtensions
{
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();
public static void Configure()
{
OneTimeRunner.Run(() =>
{
/* You can configure entity extension properties for the
* entities defined in the used modules.
*
* Example:
*
* EntityExtensionManager.AddProperty<IdentityUser, string>(
* "MyProperty",
* b =>
* {
* b.HasMaxLength(128);
* });
*
* See the documentation for more:
* https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Extending-Entities
*/
});
}
}
}

5
samples/BookStore-Modular/modules/book-management/src/Acme.BookStore.BookManagement.EntityFrameworkCore/EntityFrameworkCore/BookManagementEntityFrameworkCoreModule.cs

@ -10,6 +10,11 @@ namespace Acme.BookStore.BookManagement.EntityFrameworkCore
)]
public class BookManagementEntityFrameworkCoreModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
BookManagementEntityExtensions.Configure();
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddAbpDbContext<BookManagementDbContext>(options =>

16
samples/BookStore/src/Acme.BookStore.Domain/Users/AppUser.cs

@ -41,9 +41,19 @@ namespace Acme.BookStore.Users
#endregion
/* Add your own properties here. Example:
*
* public virtual string MyProperty { get; set; }
*/
*
* public string MyProperty { get; set; }
*
* If you add a property and using the EF Core, remember these;
*
* 1. update BookStoreDbContext.OnModelCreating
* to configure the mapping for your new property
* 2. Update BookStoreEntityExtensions to extend the IdentityUser entity
* and add your new property to the migration.
* 3. Use the Add-Migration to add a new database migration.
* 4. Run the .DbMigrator project (or use the Update-Database command) to apply
* schema change to the database.
*/
private AppUser()
{

7
samples/BookStore/src/Acme.BookStore.EntityFrameworkCore.DbMigrations/EntityFrameworkCore/BookStoreMigrationsDbContext.cs

@ -40,13 +40,6 @@ namespace Acme.BookStore.EntityFrameworkCore
builder.ConfigureFeatureManagement();
builder.ConfigureTenantManagement();
/* Configure customizations for entities from the modules included */
builder.Entity<IdentityUser>(b =>
{
b.ConfigureCustomUserProperties();
});
/* Configure your own tables/entities inside the ConfigureBookStore method */
builder.ConfigureBookStore();

2
samples/BookStore/src/Acme.BookStore.EntityFrameworkCore.DbMigrations/EntityFrameworkCore/BookStoreMigrationsDbContextFactory.cs

@ -11,6 +11,8 @@ namespace Acme.BookStore.EntityFrameworkCore
{
public BookStoreMigrationsDbContext CreateDbContext(string[] args)
{
BookStoreEntityExtensions.Configure();
var configuration = BuildConfiguration();
var builder = new DbContextOptionsBuilder<BookStoreMigrationsDbContext>()

8
samples/BookStore/src/Acme.BookStore.EntityFrameworkCore/EntityFrameworkCore/BookStoreDbContext.cs

@ -3,6 +3,7 @@ using Acme.BookStore.Users;
using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.Modeling;
using Volo.Abp.Identity;
using Volo.Abp.Users.EntityFrameworkCore;
namespace Acme.BookStore.EntityFrameworkCore
@ -41,15 +42,16 @@ namespace Acme.BookStore.EntityFrameworkCore
builder.Entity<AppUser>(b =>
{
b.ToTable("AbpUsers"); //Sharing the same table "AbpUsers" with the IdentityUser
b.ToTable(AbpIdentityDbProperties.DbTablePrefix + "Users"); //Sharing the same table "AbpUsers" with the IdentityUser
b.ConfigureFullAudited();
b.ConfigureExtraProperties();
b.ConfigureConcurrencyStamp();
b.ConfigureAbpUser();
//Moved customization to a method so we can share it with the BookStoreMigrationsDbContext class
b.ConfigureCustomUserProperties();
/* Configure mappings for your additional properties
* Also see the BookStoreEntityExtensions class
*/
});
/* Configure your own tables/entities inside the ConfigureBookStore method */

8
samples/BookStore/src/Acme.BookStore.EntityFrameworkCore/EntityFrameworkCore/BookStoreDbContextModelCreatingExtensions.cs

@ -1,8 +1,6 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Volo.Abp;
using Volo.Abp.EntityFrameworkCore.Modeling;
using Volo.Abp.Users;
namespace Acme.BookStore.EntityFrameworkCore
{
@ -21,11 +19,5 @@ namespace Acme.BookStore.EntityFrameworkCore
b.Property(x => x.Name).IsRequired().HasMaxLength(128);
});
}
public static void ConfigureCustomUserProperties<TUser>(this EntityTypeBuilder<TUser> b)
where TUser: class, IUser
{
//b.Property<string>(nameof(AppUser.MyProperty))...
}
}
}

33
samples/BookStore/src/Acme.BookStore.EntityFrameworkCore/EntityFrameworkCore/BookStoreEntityExtensions.cs

@ -0,0 +1,33 @@
using Volo.Abp.EntityFrameworkCore.Extensions;
using Volo.Abp.Identity;
using Volo.Abp.Threading;
namespace Acme.BookStore.EntityFrameworkCore
{
public static class BookStoreEntityExtensions
{
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();
public static void Configure()
{
OneTimeRunner.Run(() =>
{
/* You can configure entity extension properties for the
* entities defined in the used modules.
*
* Example:
*
* EntityExtensionManager.AddProperty<IdentityUser, string>(
* "MyProperty",
* b =>
* {
* b.HasMaxLength(128);
* });
*
* See the documentation for more:
* https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Extending-Entities
*/
});
}
}
}

5
samples/BookStore/src/Acme.BookStore.EntityFrameworkCore/EntityFrameworkCore/BookStoreEntityFrameworkCoreModule.cs

@ -27,6 +27,11 @@ namespace Acme.BookStore.EntityFrameworkCore
)]
public class BookStoreEntityFrameworkCoreModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
BookStoreEntityExtensions.Configure();
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddAbpDbContext<BookStoreDbContext>(options =>

16
samples/DashboardDemo/src/DashboardDemo.Domain/Users/AppUser.cs

@ -41,9 +41,19 @@ namespace DashboardDemo.Users
#endregion
/* Add your own properties here. Example:
*
* public virtual string MyProperty { get; set; }
*/
*
* public string MyProperty { get; set; }
*
* If you add a property and using the EF Core, remember these;
*
* 1. update BookStoreDbContext.OnModelCreating
* to configure the mapping for your new property
* 2. Update BookStoreEntityExtensions to extend the IdentityUser entity
* and add your new property to the migration.
* 3. Use the Add-Migration to add a new database migration.
* 4. Run the .DbMigrator project (or use the Update-Database command) to apply
* schema change to the database.
*/
private AppUser()
{

7
samples/DashboardDemo/src/DashboardDemo.EntityFrameworkCore.DbMigrations/EntityFrameworkCore/DashboardDemoMigrationsDbContext.cs

@ -40,13 +40,6 @@ namespace DashboardDemo.EntityFrameworkCore
builder.ConfigureFeatureManagement();
builder.ConfigureTenantManagement();
/* Configure customizations for entities from the modules included */
builder.Entity<IdentityUser>(b =>
{
b.ConfigureCustomUserProperties();
});
/* Configure your own tables/entities inside the ConfigureDashboardDemo method */
builder.ConfigureDashboardDemo();

2
samples/DashboardDemo/src/DashboardDemo.EntityFrameworkCore.DbMigrations/EntityFrameworkCore/DashboardDemoMigrationsDbContextFactory.cs

@ -11,6 +11,8 @@ namespace DashboardDemo.EntityFrameworkCore
{
public DashboardDemoMigrationsDbContext CreateDbContext(string[] args)
{
DashboardDemoEntityExtensions.Configure();
var configuration = BuildConfiguration();
var builder = new DbContextOptionsBuilder<DashboardDemoMigrationsDbContext>()

8
samples/DashboardDemo/src/DashboardDemo.EntityFrameworkCore/EntityFrameworkCore/DashboardDemoDbContext.cs

@ -3,6 +3,7 @@ using DashboardDemo.Users;
using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.Modeling;
using Volo.Abp.Identity;
using Volo.Abp.Users.EntityFrameworkCore;
namespace DashboardDemo.EntityFrameworkCore
@ -39,15 +40,16 @@ namespace DashboardDemo.EntityFrameworkCore
builder.Entity<AppUser>(b =>
{
b.ToTable("AbpUsers"); //Sharing the same table "AbpUsers" with the IdentityUser
b.ToTable(AbpIdentityDbProperties.DbTablePrefix + "Users"); //Sharing the same table "AbpUsers" with the IdentityUser
b.ConfigureFullAudited();
b.ConfigureExtraProperties();
b.ConfigureConcurrencyStamp();
b.ConfigureAbpUser();
//Moved customization to a method so we can share it with the DashboardDemoMigrationsDbContext class
b.ConfigureCustomUserProperties();
/* Configure mappings for your additional properties
* Also see the DashboardDemoEntityExtensions class
*/
});
/* Configure your own tables/entities inside the ConfigureDashboardDemo method */

8
samples/DashboardDemo/src/DashboardDemo.EntityFrameworkCore/EntityFrameworkCore/DashboardDemoDbContextModelCreatingExtensions.cs

@ -1,7 +1,5 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Volo.Abp;
using Volo.Abp.Users;
namespace DashboardDemo.EntityFrameworkCore
{
@ -20,11 +18,5 @@ namespace DashboardDemo.EntityFrameworkCore
// //...
//});
}
public static void ConfigureCustomUserProperties<TUser>(this EntityTypeBuilder<TUser> b)
where TUser: class, IUser
{
//b.Property<string>(nameof(AppUser.MyProperty))...
}
}
}

33
samples/DashboardDemo/src/DashboardDemo.EntityFrameworkCore/EntityFrameworkCore/DashboardDemoEntityExtensions.cs

@ -0,0 +1,33 @@
using Volo.Abp.EntityFrameworkCore.Extensions;
using Volo.Abp.Identity;
using Volo.Abp.Threading;
namespace DashboardDemo.EntityFrameworkCore
{
public static class DashboardDemoEntityExtensions
{
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();
public static void Configure()
{
OneTimeRunner.Run(() =>
{
/* You can configure entity extension properties for the
* entities defined in the used modules.
*
* Example:
*
* EntityExtensionManager.AddProperty<IdentityUser, string>(
* "MyProperty",
* b =>
* {
* b.HasMaxLength(128);
* });
*
* See the documentation for more:
* https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Extending-Entities
*/
});
}
}
}

5
samples/DashboardDemo/src/DashboardDemo.EntityFrameworkCore/EntityFrameworkCore/DashboardDemoEntityFrameworkCoreModule.cs

@ -27,6 +27,11 @@ namespace DashboardDemo.EntityFrameworkCore
)]
public class DashboardDemoEntityFrameworkCoreModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
DashboardDemoEntityExtensions.Configure();
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddAbpDbContext<DashboardDemoDbContext>(options =>

16
samples/EfCoreMigrationDemo/src/Acme.BookStore.Domain/Users/AppUser.cs

@ -41,9 +41,19 @@ namespace Acme.BookStore.Users
#endregion
/* Add your own properties here. Example:
*
* public virtual string MyProperty { get; set; }
*/
*
* public string MyProperty { get; set; }
*
* If you add a property and using the EF Core, remember these;
*
* 1. update BookStoreDbContext.OnModelCreating
* to configure the mapping for your new property
* 2. Update BookStoreEntityExtensions to extend the IdentityUser entity
* and add your new property to the migration.
* 3. Use the Add-Migration to add a new database migration.
* 4. Run the .DbMigrator project (or use the Update-Database command) to apply
* schema change to the database.
*/
private AppUser()
{

13
samples/EfCoreMigrationDemo/src/Acme.BookStore.EntityFrameworkCore.DbMigrations/EntityFrameworkCore/BookStoreMigrationsDbContext.cs

@ -34,19 +34,6 @@ namespace Acme.BookStore.EntityFrameworkCore
builder.ConfigureFeatureManagement();
builder.ConfigureTenantManagement();
/* Configure customizations for entities from the modules included */
//CONFIGURE THE CUSTOM ROLE PROPERTIES
builder.Entity<IdentityRole>(b =>
{
b.ConfigureCustomRoleProperties();
});
builder.Entity<IdentityUser>(b =>
{
b.ConfigureCustomUserProperties();
});
/* Configure your own tables/entities inside the ConfigureBookStore method */
builder.ConfigureBookStore();

2
samples/EfCoreMigrationDemo/src/Acme.BookStore.EntityFrameworkCore.DbMigrations/EntityFrameworkCore/BookStoreMigrationsDbContextFactory.cs

@ -11,6 +11,8 @@ namespace Acme.BookStore.EntityFrameworkCore
{
public BookStoreMigrationsDbContext CreateDbContext(string[] args)
{
BookStoreEntityExtensions.Configure();
var configuration = BuildConfiguration();
var builder = new DbContextOptionsBuilder<BookStoreMigrationsDbContext>()

8
samples/EfCoreMigrationDemo/src/Acme.BookStore.EntityFrameworkCore/EntityFrameworkCore/BookStoreDbContext.cs

@ -4,6 +4,7 @@ using Acme.BookStore.Users;
using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.Modeling;
using Volo.Abp.Identity;
using Volo.Abp.Users.EntityFrameworkCore;
namespace Acme.BookStore.EntityFrameworkCore
@ -51,12 +52,13 @@ namespace Acme.BookStore.EntityFrameworkCore
builder.Entity<AppUser>(b =>
{
b.ToTable("AbpUsers"); //Sharing the same table "AbpUsers" with the IdentityUser
b.ToTable(AbpIdentityDbProperties.DbTablePrefix + "Users"); //Sharing the same table "AbpUsers" with the IdentityUser
b.ConfigureByConvention();
b.ConfigureAbpUser();
//Moved customization to a method so we can share it with the BookStoreMigrationsDbContext class
b.ConfigureCustomUserProperties();
/* Configure mappings for your additional properties
* Also see the BookStoreEntityExtensions class
*/
});
/* Configure your own tables/entities inside the ConfigureBookStore method */

19
samples/EfCoreMigrationDemo/src/Acme.BookStore.EntityFrameworkCore/EntityFrameworkCore/BookStoreDbContextModelCreatingExtensions.cs

@ -1,10 +1,5 @@
using System;
using Acme.BookStore.Roles;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore;
using Volo.Abp;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Users;
namespace Acme.BookStore.EntityFrameworkCore
{
@ -23,17 +18,5 @@ namespace Acme.BookStore.EntityFrameworkCore
// //...
//});
}
public static void ConfigureCustomUserProperties<TUser>(this EntityTypeBuilder<TUser> b)
where TUser: class, IUser
{
//b.Property<string>(nameof(AppUser.MyProperty))...
}
public static void ConfigureCustomRoleProperties<TRole>(this EntityTypeBuilder<TRole> b)
where TRole : class, IEntity<Guid>
{
b.Property<string>(nameof(AppRole.Title)).HasMaxLength(128);
}
}
}

40
samples/EfCoreMigrationDemo/src/Acme.BookStore.EntityFrameworkCore/EntityFrameworkCore/BookStoreEntityExtensions.cs

@ -0,0 +1,40 @@
using Volo.Abp.EntityFrameworkCore.Extensions;
using Volo.Abp.Identity;
using Volo.Abp.Threading;
namespace Acme.BookStore.EntityFrameworkCore
{
public static class BookStoreEntityExtensions
{
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();
public static void Configure()
{
OneTimeRunner.Run(() =>
{
/* You can configure entity extension properties for the
* entities defined in the used modules.
*
* Example:
*
* EntityExtensionManager.AddProperty<IdentityUser, string>(
* "MyProperty",
* b =>
* {
* b.HasMaxLength(128);
* });
*
* See the documentation for more:
* https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Extending-Entities
*/
EntityExtensionManager.AddProperty<IdentityRole, string>(
nameof(AppRole.Title),
b =>
{
b.HasMaxLength(128);
});
});
}
}
}

5
samples/EfCoreMigrationDemo/src/Acme.BookStore.EntityFrameworkCore/EntityFrameworkCore/BookStoreEntityFrameworkCoreModule.cs

@ -27,6 +27,11 @@ namespace Acme.BookStore.EntityFrameworkCore
)]
public class BookStoreEntityFrameworkCoreModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
BookStoreEntityExtensions.Configure();
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddAbpDbContext<BookStoreDbContext>(options =>

Loading…
Cancel
Save