|
|
@@ -24,75 +24,75 @@ namespace Business.EntityFrameworkCore.SqlRepositories
|
|
|
{
|
|
|
_dbContext = dbContext;
|
|
|
}
|
|
|
- public async Task<int> Insert(T entity)
|
|
|
+ public int Insert(T entity)
|
|
|
{
|
|
|
_dbContext.Set<T>().Add(entity);
|
|
|
- return await _dbContext.SaveChangesAsync();
|
|
|
+ return _dbContext.SaveChanges();
|
|
|
}
|
|
|
|
|
|
- public async Task<int> Insert(List<T> entitylist)
|
|
|
+ public int Insert(List<T> entitylist)
|
|
|
{
|
|
|
- _dbContext.Set<T>().AddRange(entitylist);
|
|
|
- return await _dbContext.SaveChangesAsync();
|
|
|
+ _dbContext.Set<T>().AddRange(entitylist);
|
|
|
+ return _dbContext.SaveChanges();
|
|
|
}
|
|
|
|
|
|
- public async Task<int> Update(T entity)
|
|
|
+ public int Update(T entity)
|
|
|
{
|
|
|
_dbContext.Set<T>().Update(entity);
|
|
|
- return await _dbContext.SaveChangesAsync();
|
|
|
+ return _dbContext.SaveChanges();
|
|
|
}
|
|
|
- public async Task<int> Update(List<T> entitylist)
|
|
|
+ public int Update(List<T> entitylist)
|
|
|
{
|
|
|
_dbContext.Set<T>().UpdateRange(entitylist);
|
|
|
- return await _dbContext.SaveChangesAsync();
|
|
|
+ return _dbContext.SaveChanges();
|
|
|
}
|
|
|
|
|
|
- public async Task<int> Update(Expression<Func<T, bool>> whereLambda, Expression<Func<T, T>> entity)
|
|
|
+ public int Update(Expression<Func<T, bool>> whereLambda, Expression<Func<T, T>> entity)
|
|
|
{
|
|
|
_dbContext.Set<T>().Where(whereLambda).BatchUpdate(entity);
|
|
|
- return await _dbContext.SaveChangesAsync();
|
|
|
+ return _dbContext.SaveChanges();
|
|
|
}
|
|
|
|
|
|
- public async Task<int> Delete(Expression<Func<T, bool>> whereLambda)
|
|
|
+ public int Delete(Expression<Func<T, bool>> whereLambda)
|
|
|
{
|
|
|
_dbContext.Set<T>().Where(whereLambda).BatchDelete();
|
|
|
- return await _dbContext.SaveChangesAsync();
|
|
|
+ return _dbContext.SaveChanges();
|
|
|
}
|
|
|
|
|
|
- public async Task<bool> IsExist(Expression<Func<T, bool>> whereLambda)
|
|
|
+ public bool IsExist(Expression<Func<T, bool>> whereLambda)
|
|
|
{
|
|
|
- return await _dbContext.Set<T>().AnyAsync(whereLambda);
|
|
|
+ return _dbContext.Set<T>().Any(whereLambda);
|
|
|
}
|
|
|
|
|
|
- public async Task<List<T>> Select()
|
|
|
+ public List<T> Select()
|
|
|
{
|
|
|
- return await _dbContext.Set<T>().ToListAsync();
|
|
|
+ return _dbContext.Set<T>().ToList();
|
|
|
}
|
|
|
|
|
|
- public async Task<List<T>> Select(Expression<Func<T, bool>> whereLambda)
|
|
|
+ public List<T> Select(Expression<Func<T, bool>> whereLambda)
|
|
|
{
|
|
|
- return await _dbContext.Set<T>().Where(whereLambda).ToListAsync();
|
|
|
+ return _dbContext.Set<T>().Where(whereLambda).ToList();
|
|
|
}
|
|
|
|
|
|
- public async Task<Tuple<List<T>, int>> Select<S>(int pageSize, int pageIndex, Expression<Func<T, bool>> whereLambda, Expression<Func<T, S>> orderByLambda, bool isAsc)
|
|
|
+ public Tuple<List<T>, int> Select<S>(int pageSize, int pageIndex, Expression<Func<T, bool>> whereLambda, Expression<Func<T, S>> orderByLambda, bool isAsc)
|
|
|
{
|
|
|
var total = _dbContext.Set<T>().Where(whereLambda).Count();
|
|
|
|
|
|
if (isAsc)
|
|
|
{
|
|
|
- var entities = await _dbContext.Set<T>().Where(whereLambda)
|
|
|
+ var entities = _dbContext.Set<T>().Where(whereLambda)
|
|
|
.OrderBy<T, S>(orderByLambda)
|
|
|
.Skip(pageSize * (pageIndex - 1))
|
|
|
- .Take(pageSize).ToListAsync();
|
|
|
+ .Take(pageSize).ToList();
|
|
|
|
|
|
return new Tuple<List<T>, int>(entities, total);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- var entities =await _dbContext.Set<T>().Where(whereLambda)
|
|
|
+ var entities = _dbContext.Set<T>().Where(whereLambda)
|
|
|
.OrderByDescending<T, S>(orderByLambda)
|
|
|
.Skip(pageSize * (pageIndex - 1))
|
|
|
- .Take(pageSize).ToListAsync();
|
|
|
+ .Take(pageSize).ToList();
|
|
|
|
|
|
return new Tuple<List<T>, int>(entities, total);
|
|
|
}
|