wangxinhui
2024-12-26 78b99e5348592a29ca1393a5e13db619cc4eba56
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//using Furion.DependencyInjection;
//using SqlSugar;
//using System;
//using System.Collections.Generic;
//using System.Linq.Expressions;
//using System.Threading.Tasks;
 
//namespace WIDESEA.Common
//{
//    /// <summary>
//    /// 仓储模式对象
//    /// </summary>
//    [SuppressSniffer]
//    public partial class DbRepository<T> : SimpleClient<T> where T : class, new()
//    {
//        protected ITenant itenant = null;//多租户事务、GetConnection、IsAnyConnection等功能
 
//        public DbRepository(ISqlSugarClient context = null) : base(context)//注意这里要有默认值等于null
//        {
//            Context = SqlSugarDbContext.Db.GetConnectionScopeWithAttr<T>();//ioc注入的对象
//            itenant = SqlSugarDbContext.Db;
//        }
 
//        #region 仓储方法拓展
 
//        #region 插入
 
//        /// <summary>
//        /// 批量插入判断走普通导入还是大数据
//        /// </summary>
//        /// <param name="data">数据</param>
//        /// <param name="threshold">阈值</param>
//        /// <returns></returns>
//        public virtual async Task<int> InsertOrBulkCopy(List<T> data, int threshold = 10000)
//        {
//            if (data.Count > threshold)
//                return await Context.Fastest<T>().BulkCopyAsync(data);//大数据导入
//            else
//                return await Context.Insertable(data).ExecuteCommandAsync();//普通导入
//        }
 
//        #endregion 插入
 
//        #region 列表
 
//        /// <summary>
//        /// 获取列表指定多个字段
//        /// </summary>
//        /// <param name="whereExpression">查询条件</param>
//        /// <param name="selectExpression">查询字段</param>
//        /// <returns></returns>
//        public virtual Task<List<T>> GetListAsync(Expression<Func<T, bool>> whereExpression, Expression<Func<T, T>> selectExpression)
//        {
//            return Context.Queryable<T>().Where(whereExpression).Select(selectExpression).ToListAsync();
//        }
 
//        /// <summary>
//        /// 获取列表指定单个字段
//        /// </summary>
//        /// <param name="whereExpression">查询条件</param>
//        /// <param name="selectExpression">查询字段</param>
//        /// <returns></returns>
//        public virtual Task<List<string>> GetListAsync(Expression<Func<T, bool>> whereExpression, Expression<Func<T, string>> selectExpression)
//        {
//            return Context.Queryable<T>().Where(whereExpression).Select(selectExpression).ToListAsync();
//        }
 
//        /// <summary>
//        /// 获取列表指定单个字段
//        /// </summary>
//        /// <param name="whereExpression">查询条件</param>
//        /// <param name="selectExpression">查询字段</param>
//        /// <returns></returns>
//        public virtual Task<List<long>> GetListAsync(Expression<Func<T, bool>> whereExpression, Expression<Func<T, long>> selectExpression)
//        {
//            return Context.Queryable<T>().Where(whereExpression).Select(selectExpression).ToListAsync();
//        }
 
//        #endregion 列表
 
//        #region 单查
 
//        /// <summary>
//        /// 获取指定表的单个字段
//        /// </summary>
//        /// <param name="whereExpression">查询条件</param>
//        /// <param name="selectExpression">查询字段</param>
//        /// <returns></returns>
//        public virtual Task<string> GetFirstAsync(Expression<Func<T, bool>> whereExpression, Expression<Func<T, string>> selectExpression)
//        {
//            return Context.Queryable<T>().Where(whereExpression).Select(selectExpression).FirstAsync();
//        }
 
//        /// <summary>
//        /// 获取指定表的单个字段
//        /// </summary>
//        /// <param name="whereExpression">查询条件</param>
//        /// <param name="selectExpression">查询字段</param>
//        /// <returns></returns>
//        public virtual Task<long> GetFirstAsync(Expression<Func<T, bool>> whereExpression, Expression<Func<T, long>> selectExpression)
//        {
//            return Context.Queryable<T>().Where(whereExpression).Select(selectExpression).FirstAsync();
//        }
 
//        #endregion 单查
 
//        #endregion 仓储方法拓展
//    }
//}