diff --git a/docs/en/tutorials/modular-crm/images/abp-studio-entity-framework-core-add-migration-order.png b/docs/en/tutorials/modular-crm/images/abp-studio-entity-framework-core-add-migration-order.png new file mode 100644 index 0000000000..829ad4e022 Binary files /dev/null and b/docs/en/tutorials/modular-crm/images/abp-studio-entity-framework-core-add-migration-order.png differ diff --git a/docs/en/tutorials/modular-crm/images/abp-studio-install-module-dialog.png b/docs/en/tutorials/modular-crm/images/abp-studio-install-module-dialog.png index 9ad87c807a..404e0c7bef 100644 Binary files a/docs/en/tutorials/modular-crm/images/abp-studio-install-module-dialog.png and b/docs/en/tutorials/modular-crm/images/abp-studio-install-module-dialog.png differ diff --git a/docs/en/tutorials/modular-crm/images/sql-server-orders-database-table.png b/docs/en/tutorials/modular-crm/images/sql-server-orders-database-table.png new file mode 100644 index 0000000000..5cae53617e Binary files /dev/null and b/docs/en/tutorials/modular-crm/images/sql-server-orders-database-table.png differ diff --git a/docs/en/tutorials/modular-crm/images/visual-studio-new-migration-class-2.png b/docs/en/tutorials/modular-crm/images/visual-studio-new-migration-class-2.png new file mode 100644 index 0000000000..9593990c91 Binary files /dev/null and b/docs/en/tutorials/modular-crm/images/visual-studio-new-migration-class-2.png differ diff --git a/docs/en/tutorials/modular-crm/part-04.md b/docs/en/tutorials/modular-crm/part-04.md index 9012a1e93d..a8938fd618 100644 --- a/docs/en/tutorials/modular-crm/part-04.md +++ b/docs/en/tutorials/modular-crm/part-04.md @@ -105,8 +105,8 @@ Select the `ModularCrm.Ordering` module and check the *Install this module* opti ![abp-studio-install-module-dialog](images/abp-studio-install-module-dialog.png) -Select the `ModuleCrm.Ordering` package on the left side, `ModularCrm.Web` package on the middle area as shown in the preceding figure and click the *OK* button. +Select the `ModuleCrm.Ordering` package on the left area, `ModularCrm.Domain` package on the middle area as shown in the preceding figure and click the *OK* button. -> Since the Ordering module is not layered, we didn't install its packages to the layers of our main application. We are installing it only to the `ModularCrm.Web` since that is the final executable application of our solution and that is enough. If you build your modules as non-layered and you don't have much code in the main application's .NET solution, you can also consider to create a non-layered main application that composes these modules. +> Since the Ordering module is not layered, we didn't install its packages to the layers of our main application. We are installing it only to `ModularCrm.Domain`. In this way, we can use the Ordering module from any layer of our application since `ModularCrm.Domain` is one of the core packages of our application. If you build your modules as non-layered and you don't have much code in the main application's .NET solution, you can also consider to create a non-layered main application that composes these modules. In this part of the tutorial, we've created an empty module and added packages. In that way, you can create modules or applications with custom structure. In the next part, we will add functionality to the Ordering module. \ No newline at end of file diff --git a/docs/en/tutorials/modular-crm/part-05.md b/docs/en/tutorials/modular-crm/part-05.md index eb856210ca..ca300771dd 100644 --- a/docs/en/tutorials/modular-crm/part-05.md +++ b/docs/en/tutorials/modular-crm/part-05.md @@ -164,8 +164,68 @@ namespace ModularCrm.Ordering.Data #### Configuring the Main Application -Open the +Open the main application's solution in your IDE, find the `ModularCrmDbContext` class under the `ModularCrm.EntityFrameworkCore` project and follow the 3 steps below: -d +**(1)** Add the following attribute on top of the `ModularCrmDbContext` class: -d \ No newline at end of file +````csharp +[ReplaceDbContext(typeof(IOrderingDbContext))] +```` + +`ReplaceDbContext` attribute makes it possible to use the `ModularCrmDbContext` class in the services in the Ordering module. + +**(2)** Implement the `IOrderingDbContext` by the `ModularCrmDbContext` class: + +````csharp +public class ModularCrmDbContext : + AbpDbContext, + ITenantManagementDbContext, + IIdentityDbContext, + IProductsDbContext, + IOrderingDbContext //NEW: IMPLEMENT THE INTERFACE +{ + public DbSet Products { get; set; } + public DbSet Orders { get; set; } //NEW: ADD DBSET PROPERTY + ... +} +```` + +**(3)** Finally, call the `ConfigureOrdering()` extension method inside the `OnModelCreating` method after other `Configure...` module calls: + +````csharp +protected override void OnModelCreating(ModelBuilder builder) +{ + ... + builder.ConfigureOrdering(); //NEW: CALL THE EXTENSION METHOD +} +```` + +In this way, `ModularCrmDbContext` can be used by the Ordering module over the `IProductsDbContext` interface. This part is only needed for one time for a module. Next time, you can just add a new database migration as explained in the next section. + +#### Add a Database Migration + +Now, we can add a new database migration. You can use Entity Framework Core's `Add-Migration` (or `dotnet ef migrations add`) terminal command, but we will use ABP Studio's shortcut UI in this tutorial. + +Ensure that the solution has built. You can right-click the `ModularCrm` (under the `main` folder) on ABP Studio *Solution Runner* and select the *Dotnet CLI* -> *Graph Build* command. + +Right-click the `ModularCrm.EntityFrameworkCore` package and select the *EF Core CLI* -> *Add Migration* command: + +![abp-studio-add-entity-framework-core-migration](images/abp-studio-add-entity-framework-core-migration.png) + +The *Add Migration* command opens a new dialog to get a migration name: + +![abp-studio-entity-framework-core-add-migration-order](images/abp-studio-entity-framework-core-add-migration-order.png) + +Once you click the *OK* button, a new database migration class is added into the `Migrations` folder of the `ModularCrm.EntityFrameworkCore` project: + +![visual-studio-new-migration-class-2](images/visual-studio-new-migration-class-2.png) + +Now, you can return to ABP Studio, right-click the `ModularCrm.EntityFrameworkCore` project and select the *EF Core CLI* -> *Update Database* command: + +![abp-studio-entity-framework-core-update-database](images/abp-studio-entity-framework-core-update-database.png) + +After the operation completes, you can check your database to see the new `Orders` table has been created: + +![sql-server-products-database-table](images/sql-server-orders-database-table.png) + +TODO \ No newline at end of file