Undo changes to EfCoreMigrationDemo.

pull/3366/head
maliming 6 years ago
parent 283da6783b
commit 3d85fd0141

@ -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,19 +41,9 @@ namespace Acme.BookStore.Users
#endregion
/* Add your own properties here. Example:
*
* 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.
*/
*
* public virtual string MyProperty { get; set; }
*/
private AppUser()
{

@ -34,6 +34,19 @@ 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();

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

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

@ -1,5 +1,10 @@
using Microsoft.EntityFrameworkCore;
using System;
using Acme.BookStore.Roles;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Volo.Abp;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Users;
namespace Acme.BookStore.EntityFrameworkCore
{
@ -18,5 +23,17 @@ 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);
}
}
}

@ -1,40 +0,0 @@
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);
});
});
}
}
}

@ -27,11 +27,6 @@ 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 =>

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

Loading…
Cancel
Save