Merge pull request #3366 from abpframework/maliming/Apply-Entity-Extension-System-for-samples

apply entity extension system for samples
pull/3348/head^2
Halil İbrahim Kalkan 6 years ago committed by GitHub
commit b010535173
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -28,6 +28,7 @@ $solutionPaths = (
"../samples/BookStore-Modular/modules/book-management",
"../samples/BookStore-Modular/application",
"../samples/DashboardDemo",
"../samples/EfCoreMigrationDemo",
"../samples/MicroserviceDemo",
"../samples/RabbitMqEventBus",
"../abp_io/AbpIoLocalization"

@ -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 BookStoreEfCoreEntityExtensionMappings 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()
{

@ -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 BookStoreEfCoreEntityExtensionMappings 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()
{

@ -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();

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

@ -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 BookStoreEfCoreEntityExtensionMappings class
*/
});
/* Configure your own tables/entities inside the ConfigureBookStore method */

@ -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))...
}
}
}

@ -0,0 +1,37 @@
using Volo.Abp.Identity;
using Volo.Abp.ObjectExtending;
using Volo.Abp.Threading;
namespace Acme.BookStore.EntityFrameworkCore
{
public static class BookStoreEfCoreEntityExtensionMappings
{
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.
*
* The properties defined here becomes table fields.
* If you want to use the ExtraProperties dictionary of the entity
* instead of creating a new field, then define the property in the
* MyProjectNameDomainObjectExtensions class.
*
* Example:
*
* ObjectExtensionManager.Instance
* .MapEfCoreProperty<IdentityUser, string>(
* "MyProperty",
* b => b.HasMaxLength(128)
* );
*
* See the documentation for more:
* https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Extending-Entities
*/
});
}
}
}

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

@ -0,0 +1,36 @@
using Volo.Abp.ObjectExtending;
using Volo.Abp.Threading;
namespace Acme.BookStore.BookManagement.EntityFrameworkCore
{
public static class BookManagementEfCoreEntityExtensionMappings
{
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.
*
* The properties defined here becomes table fields.
* If you want to use the ExtraProperties dictionary of the entity
* instead of creating a new field, then define the property in the
* MyProjectNameDomainObjectExtensions class.
*
* Example:
*
* ObjectExtensionManager.Instance
* .MapEfCoreProperty<IdentityUser, string>(
* "MyProperty",
* b => b.HasMaxLength(128)
* );
*
* See the documentation for more:
* https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Extending-Entities
*/
});
}
}
}

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

@ -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 BookStoreEfCoreEntityExtensionMappings 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()
{

@ -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();

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

@ -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 BookStoreEfCoreEntityExtensionMappings class
*/
});
/* Configure your own tables/entities inside the ConfigureBookStore method */

@ -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))...
}
}
}

@ -0,0 +1,37 @@
using Volo.Abp.Identity;
using Volo.Abp.ObjectExtending;
using Volo.Abp.Threading;
namespace Acme.BookStore.EntityFrameworkCore
{
public static class BookStoreEfCoreEntityExtensionMappings
{
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.
*
* The properties defined here becomes table fields.
* If you want to use the ExtraProperties dictionary of the entity
* instead of creating a new field, then define the property in the
* MyProjectNameDomainObjectExtensions class.
*
* Example:
*
* ObjectExtensionManager.Instance
* .MapEfCoreProperty<IdentityUser, string>(
* "MyProperty",
* b => b.HasMaxLength(128)
* );
*
* See the documentation for more:
* https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Extending-Entities
*/
});
}
}
}

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

@ -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 DashboardDemoEfCoreEntityExtensionMappings 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()
{

@ -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();

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

@ -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 DashboardDemoEfCoreEntityExtensionMappings class
*/
});
/* Configure your own tables/entities inside the ConfigureDashboardDemo method */

@ -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))...
}
}
}

@ -0,0 +1,37 @@
using Volo.Abp.Identity;
using Volo.Abp.ObjectExtending;
using Volo.Abp.Threading;
namespace DashboardDemo.EntityFrameworkCore
{
public static class DashboardDemoEfCoreEntityExtensionMappings
{
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.
*
* The properties defined here becomes table fields.
* If you want to use the ExtraProperties dictionary of the entity
* instead of creating a new field, then define the property in the
* MyProjectNameDomainObjectExtensions class.
*
* Example:
*
* ObjectExtensionManager.Instance
* .MapEfCoreProperty<IdentityUser, string>(
* "MyProperty",
* b => b.HasMaxLength(128)
* );
*
* See the documentation for more:
* https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Extending-Entities
*/
});
}
}
}

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

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

@ -9,6 +9,7 @@
<ItemGroup>
<ProjectReference Include="..\..\src\Acme.BookStore.EntityFrameworkCore.DbMigrations\Acme.BookStore.EntityFrameworkCore.DbMigrations.csproj" />
<ProjectReference Include="..\..\src\Acme.BookStore.EntityFrameworkCore.DbMigrationsForSecondDb\Acme.BookStore.EntityFrameworkCore.DbMigrationsForSecondDb.csproj" />
<ProjectReference Include="..\Acme.BookStore.TestBase\Acme.BookStore.TestBase.csproj" />
</ItemGroup>

@ -1,4 +1,5 @@
using Microsoft.Data.Sqlite;
using Acme.BookStore.DbMigrationsForSecondDb.EntityFrameworkCore;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;
@ -51,6 +52,15 @@ namespace Acme.BookStore.EntityFrameworkCore
context.GetService<IRelationalDatabaseCreator>().CreateTables();
}
var secondOptions = new DbContextOptionsBuilder<BookStoreSecondMigrationsDbContext>()
.UseSqlite(connection)
.Options;
using (var context = new BookStoreSecondMigrationsDbContext(secondOptions))
{
context.GetService<IRelationalDatabaseCreator>().CreateTables();
}
return connection;
}
}

@ -12,6 +12,7 @@ using Acme.BookStore.Web;
using Acme.BookStore.Web.Menus;
using Volo.Abp;
using Volo.Abp.AspNetCore.TestBase;
using Volo.Abp.Data;
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
using Volo.Abp.UI.Navigation;
@ -38,6 +39,13 @@ namespace Acme.BookStore
{
ConfigureLocalizationServices(context.Services);
ConfigureNavigationServices(context.Services);
Configure<AbpDbConnectionOptions>(options =>
{
//SqliteConnection does not support nested transactions.
//So Dbcontext and connectionString need be same.
options.ConnectionStrings.Clear();
});
}
private static void ConfigureLocalizationServices(IServiceCollection services)

@ -46,7 +46,7 @@ namespace MyCompanyName.MyProjectName.Users
*
* If you add a property and using the EF Core, remember these;
*
* 1. update MyProjectNameDbContext.OnModelCreating
* 1. Update MyProjectNameDbContext.OnModelCreating
* to configure the mapping for your new property
* 2. Update MyProjectNameEfCoreEntityExtensionMappings to extend the IdentityUser entity
* and add your new property to the migration.

Loading…
Cancel
Save