From e2f004d3903b813b81e0e35de5c6452d3b2f0c35 Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Sat, 18 May 2019 23:46:14 +0300 Subject: [PATCH] Added comments for EF core layer. --- .../MyProjectNameMigrationsDbContext.cs | 5 +++++ .../MyProjectNameMigrationsDbContextFactory.cs | 2 ++ .../EntityFrameworkCore/MyProjectNameDbContext.cs | 13 +++++++++++++ .../MyProjectNameEntityFrameworkCoreModule.cs | 5 +++-- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/EntityFrameworkCore/MyProjectNameMigrationsDbContext.cs b/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/EntityFrameworkCore/MyProjectNameMigrationsDbContext.cs index 0999a3a3f8..df490286d3 100644 --- a/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/EntityFrameworkCore/MyProjectNameMigrationsDbContext.cs +++ b/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/EntityFrameworkCore/MyProjectNameMigrationsDbContext.cs @@ -11,6 +11,11 @@ using Volo.Abp.TenantManagement.EntityFrameworkCore; namespace MyCompanyName.MyProjectName.EntityFrameworkCore { + /* This DbContext is only used for database migrations. + * It is not used on runtime. See MyProjectNameDbContext for the runtime DbContext. + * It is a unified model that includes configuration for + * all used modules and your application. + */ public class MyProjectNameMigrationsDbContext : AbpDbContext { public MyProjectNameMigrationsDbContext(DbContextOptions options) diff --git a/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/EntityFrameworkCore/MyProjectNameMigrationsDbContextFactory.cs b/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/EntityFrameworkCore/MyProjectNameMigrationsDbContextFactory.cs index d760790fc8..b399f99cda 100644 --- a/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/EntityFrameworkCore/MyProjectNameMigrationsDbContextFactory.cs +++ b/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/EntityFrameworkCore/MyProjectNameMigrationsDbContextFactory.cs @@ -5,6 +5,8 @@ using Microsoft.Extensions.Configuration; namespace MyCompanyName.MyProjectName.EntityFrameworkCore { + /* This class is needed for EF Core console commands + * (like Add-Migration and Update-Database commands) */ public class MyProjectNameMigrationsDbContextFactory : IDesignTimeDbContextFactory { public MyProjectNameMigrationsDbContext CreateDbContext(string[] args) diff --git a/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/EntityFrameworkCore/MyProjectNameDbContext.cs b/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/EntityFrameworkCore/MyProjectNameDbContext.cs index b96691dcc7..262ed1308a 100644 --- a/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/EntityFrameworkCore/MyProjectNameDbContext.cs +++ b/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/EntityFrameworkCore/MyProjectNameDbContext.cs @@ -7,11 +7,24 @@ using Volo.Abp.Users.EntityFrameworkCore; namespace MyCompanyName.MyProjectName.EntityFrameworkCore { + /* This is your actual DbContext used on runtime. + * It includes only your entities. + * It does not include entities of the used modules, because each module has already + * its own DbContext class. If you want to share some database tables with the used modules, + * just create a structure like done for AppUser. + * + * Don't use this DbContext for database migrations since it does not contain tables of the + * used modules (as explained above). See MyProjectNameMigrationsDbContext for migrations. + */ [ConnectionStringName("Default")] public class MyProjectNameDbContext : AbpDbContext { public DbSet Users { get; set; } + /* Add DbSet properties for your Aggregate Roots / Entities here. + * Also map them inside MyProjectNameDbContextModelCreatingExtensions.ConfigureMyProjectName + */ + public MyProjectNameDbContext(DbContextOptions options) : base(options) { diff --git a/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/EntityFrameworkCore/MyProjectNameEntityFrameworkCoreModule.cs b/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/EntityFrameworkCore/MyProjectNameEntityFrameworkCoreModule.cs index bb8997aaa2..e5fb745602 100644 --- a/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/EntityFrameworkCore/MyProjectNameEntityFrameworkCoreModule.cs +++ b/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/EntityFrameworkCore/MyProjectNameEntityFrameworkCoreModule.cs @@ -30,13 +30,14 @@ namespace MyCompanyName.MyProjectName.EntityFrameworkCore context.Services.AddAbpDbContext(options => { /* Remove "includeAllEntities: true" to create - * default repositories only for aggregate roots - */ + * default repositories only for aggregate roots */ options.AddDefaultRepositories(includeAllEntities: true); }); Configure(options => { + /* The main point to change your DBMS. + * See also MyProjectNameMigrationsDbContextFactory for EF Core tooling. */ options.UseSqlServer(); }); }