mirror of
https://github.com/dotnetcore/FreeSql.git
synced 2026-02-04 15:30:53 +08:00
update
@@ -138,6 +138,48 @@ using (var uow = fsql.CreateUnitOfWork()) {
|
||||
}
|
||||
```
|
||||
|
||||
参考:在 asp.net core 中注入工作单元方法
|
||||
|
||||
```csharp
|
||||
//第一步:
|
||||
public class UnitOfWorkRepository<TEntity, TKey> : BaseRepository<TEntity, TKey>
|
||||
{
|
||||
public UnitOfWorkRepository(IFreeSql fsql, IUnitOfWork uow) : base(fsql, null, null)
|
||||
{
|
||||
this.UnitOfWork = uow;
|
||||
}
|
||||
}
|
||||
public class UnitOfWorkRepository<TEntity> : BaseRepository<TEntity, int>
|
||||
{
|
||||
public UnitOfWorkRepository(IFreeSql fsql, IUnitOfWork uow) : base(fsql, null, null)
|
||||
{
|
||||
this.UnitOfWork = uow;
|
||||
}
|
||||
}
|
||||
|
||||
//第二步:
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<IFreeSql>(fsql);
|
||||
services.AddScoped<FreeSql.IUnitOfWork>(sp => fsql.CreateUnitOfWork());
|
||||
|
||||
services.AddScoped(typeof(IReadOnlyRepository<>), typeof(UnitOfWorkRepository<>));
|
||||
services.AddScoped(typeof(IBasicRepository<>), typeof(UnitOfWorkRepository<>));
|
||||
services.AddScoped(typeof(BaseRepository<>), typeof(UnitOfWorkRepository<>));
|
||||
|
||||
services.AddScoped(typeof(IReadOnlyRepository<,>), typeof(UnitOfWorkRepository<,>));
|
||||
services.AddScoped(typeof(IBasicRepository<,>), typeof(UnitOfWorkRepository<,>));
|
||||
services.AddScoped(typeof(BaseRepository<,>), typeof(UnitOfWorkRepository<,>));
|
||||
|
||||
//批量注入程序集内的所有自建仓储类,可以根据自己需要来修改
|
||||
Assembly[] assemblies = new [] { typeof(XxxRepository).Assembly };
|
||||
if (assemblies?.Any() == true)
|
||||
foreach (var asse in assemblies)
|
||||
foreach (var repo in asse.GetTypes().Where(a => a.IsAbstract == false && typeof(UnitOfWorkRepository).IsAssignableFrom(a)))
|
||||
services.AddScoped(repo);
|
||||
}
|
||||
```
|
||||
|
||||
## 联级保存
|
||||
|
||||
请移步文档[《联级保存》](https://github.com/2881099/FreeSql/wiki/%e8%81%94%e7%ba%a7%e4%bf%9d%e5%ad%98)
|
||||
|
||||
31
入门.md
31
入门.md
@@ -94,6 +94,37 @@ fsql.Delete<Blog>()
|
||||
| UseEntityPropertyNameConvert | this | 自动转换实体属性名称 Entity Property -\> Db Filed |
|
||||
| Build\<T\> | IFreeSql\<T\> | 创建一个 IFreeSql 对象,注意:单例设计,不要重复创建 |
|
||||
|
||||
# ConnectionStrings
|
||||
|
||||
| DataType | ConnectionString |
|
||||
| --- | --- |
|
||||
| DataType.MySql | Data Source=127.0.0.1;Port=3306;User ID=root;Password=root; Initial Catalog=cccddd;Charset=utf8; SslMode=none;Min pool size=1 |
|
||||
| DataType.PostgreSQL | Host=192.168.164.10;Port=5432;Username=postgres;Password=123456; Database=tedb;Pooling=true;Minimum Pool Size=1 |
|
||||
| DataType.SqlServer | Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Min Pool Size=1 |
|
||||
| DataType.Oracle | user id=user1;password=123456; data source=//127.0.0.1:1521/XE;Pooling=true;Min Pool Size=1 |
|
||||
| DataType.Sqlite | Data Source=\|DataDirectory\|\document.db; Attachs=xxxtb.db; Pooling=true;Min Pool Size=1 |
|
||||
| DataType.OdbcMySql | Driver={MySQL ODBC 8.0 Unicode Driver}; Server=127.0.0.1;Persist Security Info=False; Trusted_Connection=Yes;UID=root;PWD=root; DATABASE=cccddd_odbc;Charset=utf8; SslMode=none;Min Pool Size=1 |
|
||||
| DataType.OdbcSqlServer | Driver={SQL Server};Server=.;Persist Security Info=False; Trusted_Connection=Yes;Integrated Security=True; DATABASE=freesqlTest_odbc; Pooling=true;Min Pool Size=1 |
|
||||
| DataType.OdbcOracle | Driver={Oracle in XE};Server=//127.0.0.1:1521/XE; Persist Security Info=False; Trusted_Connection=Yes;UID=odbc1;PWD=123456; Min Pool Size=1 |
|
||||
| DataType.OdbcPostgreSQL | Driver={PostgreSQL Unicode(x64)};Server=192.168.164.10; Port=5432;UID=postgres;PWD=123456; Database=tedb_odbc;Pooling=true;Min Pool Size=1 |
|
||||
| DataType.OdbcDameng (达梦) | Driver={DM8 ODBC DRIVER};Server=127.0.0.1:5236; Persist Security Info=False; Trusted_Connection=Yes; UID=USER1;PWD=123456789 |
|
||||
| DataType.Odbc | Driver={SQL Server};Server=.;Persist Security Info=False; Trusted_Connection=Yes;Integrated Security=True; DATABASE=freesqlTest_odbc; Pooling=true;Min pool size=1 |
|
||||
|
||||
# Providers
|
||||
|
||||
| Package Name | Version |
|
||||
|--------------| ------- |
|
||||
| FreeSql.Provider.MySql | NETStandard2.0、net45、net40 |
|
||||
| FreeSql.Provider.MySqlConnector | NETStandard2.0、net45 |
|
||||
| FreeSql.Provider.PostgreSQL | NETStandard2.0、net45 |
|
||||
| FreeSql.Provider.SqlServer | NETStandard2.0、net45、net40 |
|
||||
| FreeSql.Provider.Sqlite | NETStandard2.0、net45、net40 |
|
||||
| FreeSql.Provider.Oracle | NETStandard2.0、net45、net40 |
|
||||
| [FreeSql.Provider.Odbc](https://github.com/2881099/FreeSql/tree/master/Providers/FreeSql.Provider.Odbc) | NETStandard2.0、net45、net40 |
|
||||
| FreeSql.Extensions.LazyLoading | NETStandard2.0、net45、net40 |
|
||||
| FreeSql.Extensions.JsonMap | NETStandard2.0、net45、net40 |
|
||||
| FreeSql.Extensions.BaseEntity | NETStandard2.0 |
|
||||
|
||||
## 参考资料
|
||||
|
||||
- [《安装FreeSql》](https://github.com/2881099/FreeSql/wiki/%e5%ae%89%e8%a3%85)
|
||||
|
||||
Reference in New Issue
Block a user