diff --git a/docs/cs/EntityFrameworkCore-PostgreSQL-Integration.md b/docs/cs/Entity-Framework-Core-PostgreSQL.md similarity index 100% rename from docs/cs/EntityFrameworkCore-PostgreSQL-Integration.md rename to docs/cs/Entity-Framework-Core-PostgreSQL.md diff --git a/docs/cs/docs-nav.json b/docs/cs/docs-nav.json index 85cbf43c9d..2854966a10 100644 --- a/docs/cs/docs-nav.json +++ b/docs/cs/docs-nav.json @@ -264,7 +264,7 @@ "items": [ { "text": "PostgreSQL integrace", - "path": "EntityFrameworkCore-PostgreSQL-Integration.md" + "path": "Entity-Framework-Core-PostgreSQL.md" } ] }, diff --git a/docs/en/Data-Access.md b/docs/en/Data-Access.md index 1fd0e8a62c..c1a45366a8 100644 --- a/docs/en/Data-Access.md +++ b/docs/en/Data-Access.md @@ -2,7 +2,7 @@ ABP framework was designed as database agnostic. It can work any type of data source by the help of the [repository](Repositories.md) and [unit of work](Unit-Of-Work.md) abstractions. However, currently the following providers are implemented: -* [Entity Framework Core](Entity-Framework-Core.md) (works with [various DBMS and providers](https://docs.microsoft.com/en-us/ef/core/providers/?tabs=dotnet-core-cli).) +* [Entity Framework Core](Entity-Framework-Core.md) (works with [various DBMS and providers](https://docs.microsoft.com/en-us/ef/core/providers/).) * [MongoDB](MongoDB.md) * [Dapper](Dapper.md) diff --git a/docs/en/Entity-Framework-Core-MySQL.md b/docs/en/Entity-Framework-Core-MySQL.md new file mode 100644 index 0000000000..911db6a010 --- /dev/null +++ b/docs/en/Entity-Framework-Core-MySQL.md @@ -0,0 +1,17 @@ +# Entity Framework Core MySQL Database Provider + +This document explains how to switch to the **MySQL** database provider for **[the application startup template](Startup-Templates/Application.md)** which comes with SQL Server provider pre-configured. + +## Replace the Volo.Abp.EntityFrameworkCore.SqlServer Package + +`.EntityFrameworkCore` project in the solution depends on the [Volo.Abp.EntityFrameworkCore.SqlServer](https://www.nuget.org/packages/Volo.Abp.EntityFrameworkCore.SqlServer) NuGet package. Remove this package and add the same version of the [Volo.Abp.EntityFrameworkCore.MySQL](https://www.nuget.org/packages/Volo.Abp.EntityFrameworkCore.MySQL) package. + +## Replace the Module Dependency + +Find ***YourProjectName*EntityFrameworkCoreModule** class inside the `.EntityFrameworkCore` project, remove `typeof(AbpEntityFrameworkCoreSqlServerModule)` from the `DependsOn` attribute, add `typeof(AbpEntityFrameworkCoreMySQLModule)` (also replace `using Volo.Abp.EntityFrameworkCore.SqlServer;` with `using Volo.Abp.EntityFrameworkCore.MySQL;`). + +## Call UseMySQL + +Find `UseSqlServer()` calls in your solution, replace with `UseMySQL()` + +TODO \ No newline at end of file diff --git a/docs/en/EntityFrameworkCore-PostgreSQL-Integration.md b/docs/en/Entity-Framework-Core-PostgreSQL.md similarity index 100% rename from docs/en/EntityFrameworkCore-PostgreSQL-Integration.md rename to docs/en/Entity-Framework-Core-PostgreSQL.md diff --git a/docs/en/Entity-Framework-Core.md b/docs/en/Entity-Framework-Core.md index e608736bcd..b73e16a3e5 100644 --- a/docs/en/Entity-Framework-Core.md +++ b/docs/en/Entity-Framework-Core.md @@ -28,6 +28,17 @@ namespace MyCompany.MyProject > Note: Instead, you can directly download a [startup template](https://abp.io/Templates) with EF Core pre-installed. +### Database Management System Selection + +Entity Framework Core supports various database management systems ([see all](https://docs.microsoft.com/en-us/ef/core/providers/)). ABP framework and this document doesn't depend on any specific DBMS. + +If you are creating a reusable library, avoid to depend on a specific DBMS package. However, in a final application you eventually will select a DBMS. + +ABP framework provides integration packages for some common DBMSs to make the configuration a bit easier. [The startup templates](Startup-Templates/Index.md) come with **SQL Server (localdb) pre-configured**. See the following documents to learn how to configure for the other DBMS providers: + +* [MySQL](Entity-Framework-Core-MySQL.md) +* [PostgreSQL](Entity-Framework-Core-PostgreSQL.md) + ## Creating DbContext You can create your DbContext as you normally do. It should be derived from `AbpDbContext` as shown below: @@ -62,7 +73,7 @@ public class MyDbContext : AbpDbContext } ``` -If you don't configure, the `Default` connection string is used. If you configure a specific connection string name, but not define this connection string name in the application configuration then it fallbacks to the `Default` connection string. +If you don't configure, the `Default` connection string is used. If you configure a specific connection string name, but not define this connection string name in the application configuration then it fallbacks to the `Default` connection string (see [the connection strings document](Connection-Strings.md) for more information). ## Registering DbContext To Dependency Injection @@ -126,7 +137,8 @@ public class BookManager : DomainService { private readonly IRepository _bookRepository; - public BookManager(IRepository bookRepository) //inject default repository + //inject default repository to the constructor + public BookManager(IRepository bookRepository) { _bookRepository = bookRepository; } @@ -142,7 +154,8 @@ public class BookManager : DomainService Type = type }; - await _bookRepository.InsertAsync(book); //Use a standard repository method + //Use a standard repository method + await _bookRepository.InsertAsync(book); return book; } @@ -153,9 +166,9 @@ This sample uses `InsertAsync` method to insert a new entity to the database. ### Add Custom Repositories -Default generic repositories are powerful enough in most cases (since they implement `IQueryable`). However, you may need to create a custom repository to add your own repository methods. +Default generic repositories are powerful enough in most cases (since they implement `IQueryable`). However, you may need to create a custom repository to add your own repository methods. Assume that you want to delete all books by type. -Assume that you want to delete all books by type. It's suggested to define an interface for your custom repository: +It's suggested to define an interface for your custom repository: ````csharp public interface IBookRepository : IRepository @@ -187,21 +200,23 @@ public class BookRepository : EfCoreRepository, Now, it's possible to [inject](Dependency-Injection.md) the `IBookRepository` and use the `DeleteBooksByType` method when needed. -#### Override Default Generic Repository +#### Override the Default Generic Repository Even if you create a custom repository, you can still inject the default generic repository (`IRepository` for this example). Default repository implementation will not use the class you have created. -If you want to replace default repository implementation with your custom repository, do it inside `AddAbpDbContext` options: +If you want to replace default repository implementation with your custom repository, do it inside the `AddAbpDbContext` options: ````csharp context.Services.AddAbpDbContext(options => { options.AddDefaultRepositories(); - options.AddRepository(); //Replaces IRepository + + //Replaces IRepository + options.AddRepository(); }); ```` -This is especially important when you want to **override a base repository method** to customize it. For instance, you may want to override `DeleteAsync` method to delete an entity in a more efficient way: +This is especially important when you want to **override a base repository method** to customize it. For instance, you may want to override `DeleteAsync` method to delete a specific entity in a more efficient way: ````csharp public override async Task DeleteAsync( @@ -215,7 +230,7 @@ public override async Task DeleteAsync( ### Access to the EF Core API -In most cases, you want to hide EF Core APIs behind a repository (this is the main purpose of the repository). However, if you want to access the DbContext instance over the repository, you can use `GetDbContext()` or `GetDbSet()` extension methods. Example: +In most cases, you want to hide EF Core APIs behind a repository (this is the main purpose of the repository pattern). However, if you want to access the `DbContext` instance over the repository, you can use `GetDbContext()` or `GetDbSet()` extension methods. Example: ````csharp public class BookService @@ -243,9 +258,9 @@ public class BookService #### Set Default Repository Classes -Default generic repositories are implemented by `EfCoreRepository` class by default. You can create your own implementation and use it for default repository implementation. +Default generic repositories are implemented by `EfCoreRepository` class by default. You can create your own implementation and use it for all the default repository implementations. -First, define your repository classes like that: +First, define your default repository classes like that: ```csharp public class MyRepositoryBase @@ -271,7 +286,7 @@ public class MyRepositoryBase First one is for [entities with composite keys](Entities.md), second one is for entities with single primary key. -It's suggested to inherit from the `EfCoreRepository` class and override methods if needed. Otherwise, you will have to implement all standard repository methods manually. +It's suggested to inherit from the `EfCoreRepository` class and override methods if needed. Otherwise, you will have to implement all the standard repository methods manually. Now, you can use `SetDefaultRepositoryClasses` option: @@ -282,6 +297,7 @@ context.Services.AddAbpDbContext(options => typeof(MyRepositoryBase<,>), typeof(MyRepositoryBase<>) ); + //... }); ``` @@ -316,7 +332,7 @@ public class BookRepository : EfCoreRepository, } ```` -One advantage of using interface for a DbContext is then it becomes replaceable by another implementation. +One advantage of using an interface for a DbContext is then it will be replaceable by another implementation. #### Replace Other DbContextes diff --git a/docs/en/docs-nav.json b/docs/en/docs-nav.json index db194177a9..c4a864f4de 100644 --- a/docs/en/docs-nav.json +++ b/docs/en/docs-nav.json @@ -265,7 +265,7 @@ "items": [ { "text": "PostgreSQL Integration", - "path": "EntityFrameworkCore-PostgreSQL-Integration.md" + "path": "Entity-Framework-Core-PostgreSQL.md" } ] }, diff --git a/docs/pt-BR/docs-nav.json b/docs/pt-BR/docs-nav.json index 8e7eaf62af..a189b83c09 100644 --- a/docs/pt-BR/docs-nav.json +++ b/docs/pt-BR/docs-nav.json @@ -249,7 +249,7 @@ "items": [ { "text": "Integração do PostgreSQL", - "path": "EntityFrameworkCore-PostgreSQL-Integration.md" + "path": "Entity-Framework-Core-PostgreSQL.md" } ] }, diff --git a/docs/zh-Hans/EntityFrameworkCore-PostgreSQL-Integration.md b/docs/zh-Hans/Entity-Framework-Core-PostgreSQL.md similarity index 100% rename from docs/zh-Hans/EntityFrameworkCore-PostgreSQL-Integration.md rename to docs/zh-Hans/Entity-Framework-Core-PostgreSQL.md diff --git a/docs/zh-Hans/docs-nav.json b/docs/zh-Hans/docs-nav.json index dd740f6c3b..301af0fd6a 100644 --- a/docs/zh-Hans/docs-nav.json +++ b/docs/zh-Hans/docs-nav.json @@ -254,7 +254,7 @@ "items": [ { "text": "PostgreSQL 集成", - "path": "EntityFrameworkCore-PostgreSQL-Integration.md" + "path": "Entity-Framework-Core-PostgreSQL.md" } ] },