Browse Source

Db mapping for the orders

pull/20822/head
Halil İbrahim Kalkan 2 years ago
parent
commit
9ba0e5377d
  1. BIN
      docs/en/tutorials/modular-crm/images/abp-studio-entity-framework-core-add-migration-order.png
  2. BIN
      docs/en/tutorials/modular-crm/images/abp-studio-install-module-dialog.png
  3. BIN
      docs/en/tutorials/modular-crm/images/sql-server-orders-database-table.png
  4. BIN
      docs/en/tutorials/modular-crm/images/visual-studio-new-migration-class-2.png
  5. 4
      docs/en/tutorials/modular-crm/part-04.md
  6. 66
      docs/en/tutorials/modular-crm/part-05.md

BIN
docs/en/tutorials/modular-crm/images/abp-studio-entity-framework-core-add-migration-order.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
docs/en/tutorials/modular-crm/images/abp-studio-install-module-dialog.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 98 KiB

After

Width:  |  Height:  |  Size: 75 KiB

BIN
docs/en/tutorials/modular-crm/images/sql-server-orders-database-table.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

BIN
docs/en/tutorials/modular-crm/images/visual-studio-new-migration-class-2.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

4
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.

66
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
````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<ModularCrmDbContext>,
ITenantManagementDbContext,
IIdentityDbContext,
IProductsDbContext,
IOrderingDbContext //NEW: IMPLEMENT THE INTERFACE
{
public DbSet<Product> Products { get; set; }
public DbSet<Order> 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
Loading…
Cancel
Save