Skip to content

Commit

Permalink
Merge branch 'main' of github.com:2881099/FreeSql.Wiki.VuePress
Browse files Browse the repository at this point in the history
  • Loading branch information
luoyunchong committed Jan 30, 2024
2 parents fce35dd + 1137abb commit fe83bc9
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/.vuepress/navbar/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { navbar } from "vuepress-theme-hope";

export const zhNavbarConfig = navbar([
{
text: '指南',
text: '文档',
link: '/guide/',
icon: "creative",
},
Expand Down
1 change: 1 addition & 0 deletions docs/guide/ado.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ fsql.Ado.CommandFluent("dbo.GetICMaxNum")
p2 = p; //Output 参数
p.DbType = DbType.Int32;
p.Direction = ParameterDirection.Output;
(p as SqlParameter).Size = 50; //具体的数据库参数
})
.ExecuteNonQuery(); //.Query<T>() 或者 .ExecuteDataTable() 或者 ...
Expand Down
1 change: 1 addition & 0 deletions docs/guide/freescheduler.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ static Scheduler scheduler = new FreeSchedulerBuilder()
| Method | 说明 |
| -- | -- |
| OnExecuting(Action\<TaskInfo\> executing) | 任务触发 |
| UseTimeZone() | 设置时区 |
| UseStorage() | 基于 数据库或者 Redis 持久化 |
| UseCluster() | 开启集群(依赖 Redis),支持跨进程互通 |
| UseCustomInterval() | 自定义间隔(可实现 cron) |
Expand Down
46 changes: 46 additions & 0 deletions docs/guide/repository.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,52 @@ repo.CompareState(item) 可获取 item 的状态变化信息
Dictionary<string, object[]> CompareState(TEntity newdata);
```

## Ioc + 登陆信息

repo.DbContextOptions.AuditValue 适合与 Ioc AddScoped 信息结合。

如下示例:使用仓储插入/更新时自动使用登陆信息

```csharp
services.AddSingleton(fsql);
services.AddScoped(r => new MyRepositoryOptions
{
AuditValue = e => {
var user = r.GetService<User>();
if (user == null) return;
if (e.AuditValueType == AuditValueType.Insert &&
e.Object is IEntityCreated obj1 && obj1 != null) {
obj1.CreatedUserId = user.Id;
obj1.CreatedUserName = user.Username;
}
if (e.AuditValueType == AuditValueType.Update &&
e.Object is IEntityModified obj2 && obj2 != null) {
obj2.ModifiedUserId = user.Id;
obj2.ModifiedUserName = user.Username;
}
}
});
services.AddScoped(typeof(IBaseRepository<>), typeof(MyRepository<>));
services.AddScoped(typeof(IBaseRepository<,>), typeof(MyRepository<,>));

//以下实现 MyRepository
class MyRepository<TEntity, TKey> : BaseRepository<TEntity, TKey> where TEntity : class
{
public MyRepository(IFreeSql fsql, MyRepositoryOptions options) : base(fsql, null, null)
{
if (options?.AuditValue != null) DbContextOptions.AuditValue += (_, e) => options.AuditValue(e);
}
}
class MyRepository<TEntity> : MyRepository<TEntity, long> where TEntity : class
{
public MyRepository(IFreeSql fsql, MyRepositoryOptions options) : base(fsql, options) { }
}
class MyRepositoryOptions
{
public Action<DbContextAuditValueEventArgs> AuditValue { get; set; }
}
```

## 过滤与验证

假设我们有 User(用户)、Topic(主题)两个实体,定义了两个仓储:
Expand Down
2 changes: 2 additions & 0 deletions docs/reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
| 方法 | 返回值 | 说明 |
| -- | -- | -- |
| UseConnectionString | this | 设置连接串 |
| UseAdoConnectionPool | this | 设置连接池方案(默认 false,远程访问建议设置 true) |
| UseSlave | this | 设置从数据库,支持多个 |
| UseSlaveWeight | this | 设置从数据库权重 |
| UseConnectionFactory | this | 设置自定义数据库连接对象(放弃内置对象连接池技术) |
Expand All @@ -17,6 +18,7 @@
| UseMonitorCommand | this | 监视全局 SQL 执行前后 |
| UseMappingPriority | this | 指定映射优先级(默认 Aop < FluentApi < Attribute) |
| **UseNameConvert** | this | 自动转换名称 Entity -\> Db |
| UseQuoteSqlName | this | SQL名称是否使用 \[\] `` "" |
| UseExitAutoDisposePool | this | 监听 AppDomain.CurrentDomain.ProcessExit/Console.CancelKeyPress 事件自动释放连接池 (默认true) |
| Build\<T\> | IFreeSql\<T\> | 创建一个 IFreeSql 对象,注意:单例设计,不要重复创建 |

Expand Down
8 changes: 8 additions & 0 deletions docs/reference/change-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

大约每月一次版本号,暂时以修复 bug 为主

## v3.2.811

- 增加 DbContextOptions.AuditValue 基于 Ioc Scoped 审计值;
- 修复 Enum -> MapType(string) + GroupBy 解析问题;#1727
- 修复 MySql AsTreeCte pathSelector 别名问题;
- 修复 ClickHouse UpdateDict 报错问题;#1712
- 修复 MsAccess 日期问题;#1724 #1725

## v3.2.810

- 修复 GroupBy + WithTempQuery 别名问题;
Expand Down

0 comments on commit fe83bc9

Please sign in to comment.