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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
| public class DbRepository<T>:IDbRepository<T> where T : class, ISoftDelete, IAuditableEntity, new() { private readonly ACDSqlSugarClient DbContext;
public DbRepository(ACDSqlSugarClient client) { DbContext = client; }
public ISugarQueryable<T> AsQueryable() { return DbContext.Queryable<T>().Where(x => !x.IsDeleted); }
public IInsertable<T> AsInsertable(T insertObj) { return DbContext.Insertable(insertObj); }
public IInsertable<T> AsInsertable(T[] insertObjs) { return DbContext.Insertable(insertObjs); }
public IInsertable<T> AsInsertable(List<T> insertObjs) { return DbContext.Insertable(insertObjs); }
public IUpdateable<T> AsUpdateable(T updateObj) { return DbContext.Updateable(updateObj); }
public IUpdateable<T> AsUpdateable(T[] updateObjs) { return DbContext.Updateable(updateObjs); }
public IUpdateable<T> AsUpdateable(List<T> updateObjs) { return DbContext.Updateable(updateObjs); }
public IDeleteable<T> AsDeleteable() { return DbContext.Deleteable<T>(); } public IDeleteable<T> AsDeleteable(T deleteObj) { return DbContext.Deleteable(deleteObj); }
public List<T> GetList() { return AsQueryable().ToList(); }
public Task<List<T>> GetListAsync() { return AsQueryable().ToListAsync(); }
public List<T> GetList(Expression<Func<T, bool>> whereExpression) { return AsQueryable().Where(whereExpression).ToList(); }
public Task<List<T>> GetListAsync(Expression<Func<T, bool>> whereExpression) { return AsQueryable().Where(whereExpression).ToListAsync(); }
public List<T> GetList(Expression<Func<T, bool>> whereExpression, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc) { return AsQueryable().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(whereExpression).ToList(); }
public Task<List<T>> GetListAsync(Expression<Func<T, bool>> whereExpression, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc) { return AsQueryable().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(whereExpression).ToListAsync(); }
public List<T> GetPageList(Expression<Func<T, bool>> whereExpression, PageModel page) { int count = 0; var result = AsQueryable().Where(whereExpression).ToPageList(page.PageIndex, page.PageSize, ref count); page.TotalCount = count; return result; }
public Task<List<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, PageModel page) { RefAsync<int> count = 0; var result = AsQueryable().Where(whereExpression).ToPageListAsync(page.PageIndex, page.PageSize, count); page.TotalCount = count; return result; }
public List<T> GetPageList(Expression<Func<T, bool>> whereExpression, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc) { int count = 0; var result = AsQueryable().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(whereExpression).ToPageList(page.PageIndex, page.PageSize, ref count); page.TotalCount = count; return result; }
public Task<List<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc) { RefAsync<int> count = 0; var result = AsQueryable().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(whereExpression).ToPageListAsync(page.PageIndex, page.PageSize, count); page.TotalCount = count; return result; }
public int Count(Expression<Func<T, bool>> whereExpression) { return AsQueryable().Count(whereExpression); }
public Task<int> CountAsync(Expression<Func<T, bool>> whereExpression) { return AsQueryable().CountAsync(whereExpression); }
public T GetById(dynamic id) { return AsQueryable().InSingle(id); }
public T GetSingle(Expression<Func<T, bool>> whereExpression) { return AsQueryable().Single(whereExpression); }
public Task<T> GetSingleAsync(Expression<Func<T, bool>> whereExpression) { return AsQueryable().SingleAsync(whereExpression); }
public T GetFirst(Expression<Func<T, bool>> whereExpression) { return AsQueryable().First(whereExpression); }
public Task<T> GetFirstAsync(Expression<Func<T, bool>> whereExpression) { return AsQueryable().FirstAsync(whereExpression); }
public bool IsAny(Expression<Func<T, bool>> whereExpression) { return AsQueryable().Any(whereExpression); }
public Task<bool> IsAnyAsync(Expression<Func<T, bool>> whereExpression) { return AsQueryable().AnyAsync(whereExpression); }
public bool Insert(T insertObj) { return AsInsertable(insertObj).ExecuteCommand() > 0; }
public async Task<bool> InsertAsync(T insertObj) { return await AsInsertable(insertObj).ExecuteCommandAsync() > 0; }
public bool InsertRange(List<T> insertObjs) { return AsInsertable(insertObjs).ExecuteCommand() > 0; }
public async Task<bool> InsertRangeAsync(List<T> insertObjs) { return await AsInsertable(insertObjs).ExecuteCommandAsync() > 0; }
public bool InsertRange(T[] insertObjs) { return AsInsertable(insertObjs).ExecuteCommand() > 0; }
public async Task<bool> InsertRangeAsync(T[] insertObjs) { return await AsInsertable(insertObjs).ExecuteCommandAsync() > 0; }
public int InsertReturnIdentity(T insertObj) { return AsInsertable(insertObj).ExecuteReturnIdentity(); }
public Task<long> InsertReturnIdentityAsync(T insertObj) { return AsInsertable(insertObj).ExecuteReturnBigIdentityAsync(); }
public bool Delete(Expression<Func<T, bool>> whereExpression) { return AsDeleteable().Where(whereExpression).ExecuteCommandHasChange(); }
public Task<bool> DeleteAsync(Expression<Func<T, bool>> whereExpression) { return AsDeleteable().Where(whereExpression).ExecuteCommandHasChangeAsync(); }
public bool Delete(T deleteObj) { return AsDeleteable(deleteObj).ExecuteCommandHasChange(); }
public Task<bool> DeleteAsync(T deleteObj) { return AsDeleteable(deleteObj).ExecuteCommandHasChangeAsync(); }
public bool DeleteById(dynamic id) { return AsDeleteable().In(id).ExecuteCommandHasChange(); }
public Task<bool> DeleteByIdAsync(dynamic id) { return AsDeleteable().In(id).ExecuteCommandHasChangeAsync(); }
public bool DeleteByIds(dynamic[] ids) { return AsDeleteable().In(ids).ExecuteCommandHasChange(); }
public Task<bool> DeleteByIdsAsync(dynamic[] ids) { return AsDeleteable().In(ids).ExecuteCommandHasChangeAsync(); }
public bool Update(T t, Expression<Func<T, object>> columns, Expression<Func<T, bool>> whereExpression) { return AsUpdateable(t).UpdateColumns(columns).Where(whereExpression).ExecuteCommandHasChange(); }
public Task<bool> UpdateAsync(T t, Expression<Func<T, object>> columns, Expression<Func<T, bool>> whereExpression) { return AsUpdateable(t).UpdateColumns(columns).Where(whereExpression).ExecuteCommandHasChangeAsync(); }
public bool Update(T updateObj) { return AsUpdateable(updateObj).ExecuteCommandHasChange(); }
public Task<bool> UpdateAsync(T updateObj) { return AsUpdateable(updateObj).ExecuteCommandHasChangeAsync(); }
public bool UpdateRange(T[] updateObjs) { return AsUpdateable(updateObjs).ExecuteCommandHasChange(); }
public Task<bool> UpdateRangeAsync(T[] updateObjs) { return AsUpdateable(updateObjs).ExecuteCommandHasChangeAsync(); }
public DbResult<T2> UseTran<T2>(Func<T2> action) { return DbContext.Ado.UseTran(action); }
public DbResult<bool> UseTran(Action action) { return DbContext.Ado.UseTran(action); }
public Task<DbResult<T2>> UseTranAsync<T2>(Func<Task<T2>> action, Action<Exception> errorCallBack = null) { return DbContext.Ado.UseTranAsync(action, errorCallBack); }
public Task<DbResult<bool>> UseTranAsync(Func<Task> action, Action<Exception> errorCallBack = null) { return DbContext.Ado.UseTranAsync(action, errorCallBack); }
public void BeginTran() { DbContext.Ado.BeginTran(); }
public void CommitTran() { DbContext.Ado.CommitTran(); }
public void RollbackTran() { DbContext.Ado.RollbackTran(); } }
|