mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-05-01 06:42:50 +08:00

> 文档:https://github.com/2881099/FreeSql/wiki/DbContext#%E5%AE%9E%E4%BD%93%E5%8F%98%E5%8C%96%E4%BA%8B%E4%BB%B6 - 补充 Aop.CurdBefore 事件参数 Table 实体类型的元数据;
44 lines
1.4 KiB
C#
44 lines
1.4 KiB
C#
using FreeSql;
|
|
using System;
|
|
using System.Collections.Concurrent;
|
|
using System.Collections.Generic;
|
|
|
|
public static class FreeSqlDbContextExtensions
|
|
{
|
|
|
|
/// <summary>
|
|
/// 创建普通数据上下文档对象
|
|
/// </summary>
|
|
/// <param name="that"></param>
|
|
/// <returns></returns>
|
|
public static DbContext CreateDbContext(this IFreeSql that)
|
|
{
|
|
return new FreeContext(that);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 不跟踪查询的实体数据(在不需要更新其数据时使用),可提长查询性能
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <param name="select"></param>
|
|
/// <returns></returns>
|
|
public static ISelect<T> NoTracking<T>(this ISelect<T> select) where T : class
|
|
{
|
|
return select.TrackToList(null);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置 DbContext 选项设置
|
|
/// </summary>
|
|
/// <param name="that"></param>
|
|
/// <param name="options"></param>
|
|
public static IFreeSql SetDbContextOptions(this IFreeSql that, Action<DbContextOptions> options)
|
|
{
|
|
if (options == null) return that;
|
|
var cfg = _dicSetDbContextOptions.GetOrAdd(that, t => new DbContextOptions());
|
|
options(cfg);
|
|
_dicSetDbContextOptions.AddOrUpdate(that, cfg, (t, o) => cfg);
|
|
return that;
|
|
}
|
|
internal static ConcurrentDictionary<IFreeSql, DbContextOptions> _dicSetDbContextOptions = new ConcurrentDictionary<IFreeSql, DbContextOptions>();
|
|
} |