using FreeSql; using System; using System.Collections.Generic; using System.Collections.Concurrent; using System.Text; using System.Linq.Expressions; public static class IFreeSqlExtenssions { /// /// 返回默认仓库类 /// /// /// /// /// 数据过滤 + 验证 /// public static DefaultRepository GetRepository(this IFreeSql that, Expression> filter = null) where TEntity : class { if (filter != null) return new DefaultRepository(that, filter); return dicGetRepository .GetOrAdd(typeof(TEntity), key1 => new ConcurrentDictionary()) .GetOrAdd(typeof(TKey), key2 => new DefaultRepository(that, null)) as DefaultRepository; } static ConcurrentDictionary > dicGetRepository = new ConcurrentDictionary>(); /// /// 返回仓库类,适用 Insert 方法无须返回插入的数据 /// /// /// /// 数据过滤 + 验证 /// 分表规则,参数:旧表名;返回:新表名 https://github.com/2881099/FreeSql/wiki/Repository /// public static GuidRepository GetGuidRepository(this IFreeSql that, Expression> filter = null, Func asTable = null) where TEntity : class { if (filter != null || asTable != null) return new GuidRepository(that, filter, asTable); return dicGetGuidRepository .GetOrAdd(typeof(TEntity), key1 => new GuidRepository(that, null, null)) as GuidRepository; } static ConcurrentDictionary dicGetGuidRepository = new ConcurrentDictionary(); /// /// 合并两个仓储的设置,以便查询 /// /// /// /// /// /// public static ISelect FromRepository(this ISelect that, BaseRepository repos) where TEntity : class where T2 : class { return that.AsTable(repos.AsTableSelectInternal).Where(repos.FilterInternal); } }