- 增加 FreeSql.Provider.Custom 自定义适配访问任何数据库;

This commit is contained in:
2881099
2021-02-05 18:20:38 +08:00
parent 7aedc52cf3
commit 082dcf1fa4
18 changed files with 1509 additions and 193 deletions

View File

@ -0,0 +1,30 @@
FreeSql.Provider.Custom 实现自定义适配器,访问所有数据库。
# 通用实现
通用实现为了让用户自己适配更多的数据库,比如连接 mssql 2000、db2 等数据库,牺牲了一些功能:
- 不支持 CodeFirst 自动迁移
- 不支持 DbFirst 接口方法的实现
- 不支持 原来的分页方法,需要自行判断 id 进行分页
- 只支持较少的基础类型bool,sbyte,short,int,long,byte,ushort,uint,ulong,double,float,decimal,DateTime,byte[],string,Guid
使用者只需求重写类 FreeSql.Custom.CustomAdapter 就可以自定义访问不同的数据库。
我们默认做了一套 sqlserver 的语法和映射适配,代码在 [CustomAdapter.cs](https://github.com/2881099/FreeSql/blob/master/Providers/FreeSql.Provider.Custom/CustomAdapter.cs),请查看代码了解。
```csharp
class Mssql2000Adapter : FreeSql.Custom.CustomAdapter
{
public override string InsertAfterGetIdentitySql => "SELECT SCOPE_IDENTITY()";
//可以重写更多的设置
}
static IFreeSql fsql = new FreeSql.FreeSqlBuilder()
.UseConnectionString(FreeSql.DataType.Custom, () => new SqlConnection(@"Data Source=..."))
.Build(); //be sure to define as singleton mode
fsql.SetCustomAdapter(new Mssql2000Adapter());
```
适配好新的 CustomAdapter 后,请在 FreeSqlBuilder.Build 之后调用 IFreeSql.SetCustomAdapter 方法生效。