mirror of
https://github.com/dotnetcore/FreeSql.git
synced 2026-02-11 10:50:56 +08:00
Updated Repository Layer (markdown)
@@ -1,7 +1,5 @@
|
|||||||
[中文](Repository) | **English**
|
[中文](Repository) | **English**
|
||||||
|
|
||||||
FreeSql.Repository 作为扩展,实现了通用仓储层功能。与其他规范标准一样,仓储层也有相应的规范定义。FreeSql.Repository 参考 abp vnext 接口,定义和实现基础的仓储层(CURD),应该算比较通用的方法吧。
|
|
||||||
|
|
||||||
As an extension, FreeSql.Repository realizes the functions of the common DAL. There is a certain standard definition for the repository layer. FreeSql.Repository refers to the interface design of Abp vNext, defines and implements the basic repository layer for CURD operations.
|
As an extension, FreeSql.Repository realizes the functions of the common DAL. There is a certain standard definition for the repository layer. FreeSql.Repository refers to the interface design of Abp vNext, defines and implements the basic repository layer for CURD operations.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
@@ -13,12 +11,12 @@ As an extension, FreeSql.Repository realizes the functions of the common DAL. Th
|
|||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
环境1:.NET Core 或 .NET 5.0+
|
Situation 1: .NET Core or .NET 5.0+
|
||||||
```bash
|
```bash
|
||||||
dotnet add package FreeSql.Repository
|
dotnet add package FreeSql.Repository
|
||||||
```
|
```
|
||||||
|
|
||||||
环境2、.NET Framework
|
Situation 2、.NET Framework
|
||||||
```bash
|
```bash
|
||||||
Install-Package FreeSql.DbContext
|
Install-Package FreeSql.DbContext
|
||||||
```
|
```
|
||||||
@@ -28,8 +26,10 @@ Install-Package FreeSql.DbContext
|
|||||||
```csharp
|
```csharp
|
||||||
static IFreeSql fsql = new FreeSql.FreeSqlBuilder()
|
static IFreeSql fsql = new FreeSql.FreeSqlBuilder()
|
||||||
.UseConnectionString(FreeSql.DataType.Sqlite, connectionString)
|
.UseConnectionString(FreeSql.DataType.Sqlite, connectionString)
|
||||||
.UseAutoSyncStructure(true) //自动迁移实体的结构到数据库
|
//Automatically synchronize the entity structure to the database.
|
||||||
.Build(); //请务必定义成 Singleton 单例模式
|
.UseAutoSyncStructure(true)
|
||||||
|
//Be sure to define as singleton mode
|
||||||
|
.Build();
|
||||||
|
|
||||||
public class Song {
|
public class Song {
|
||||||
[Column(IsIdentity = true)]
|
[Column(IsIdentity = true)]
|
||||||
@@ -40,26 +40,26 @@ public class Song {
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
方法1、IFreeSql 的扩展方法;
|
Method 1. The extension method of IFreeSql
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
var curd = fsql.GetRepository<Song>();
|
var curd = fsql.GetRepository<Song>();
|
||||||
```
|
```
|
||||||
|
|
||||||
> 注意:Repository对象多线程不安全,因此不应在多个线程上同时对其执行工作。
|
> Note: Repository objects are not safe under multiple threads, so you should not operate them on multiple threads at the same time.
|
||||||
- 不支持从不同的线程同时使用同一仓储实例
|
- Does not support using the same repository instance in different threads at the same time
|
||||||
|
|
||||||
方法2、继承实现;
|
Method 2. Inheritance
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
public class SongRepository : BaseRepository<Song, int> {
|
public class SongRepository : BaseRepository<Song, int> {
|
||||||
public SongRepository(IFreeSql fsql) : base(fsql, null, null) {}
|
public SongRepository(IFreeSql fsql) : base(fsql, null, null) {}
|
||||||
|
|
||||||
//在这里增加 CURD 以外的方法
|
//Do something except CURD.
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
方法3、依赖注入;
|
Method 3: Dependency Injection
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
public void ConfigureServices(IServiceCollection services) {
|
public void ConfigureServices(IServiceCollection services) {
|
||||||
@@ -78,9 +78,9 @@ public SongsController(IBaseRepository<Song> repos1) {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
> 依赖注入的方式可实现全局【过滤与验证】的设定,方便租户功能的设计;
|
> Dependency injection can realize the global setting of **filtering and verification**, which is convenient for the design of tenant functions.
|
||||||
|
|
||||||
更多资料:[《过滤器、全局过滤器》](%e8%bf%87%e6%bb%a4%e5%99%a8)
|
For more information: [《Filters and Global Filters》](Filters-and-Global-Filters)
|
||||||
|
|
||||||
## State Management
|
## State Management
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user