修改仓储

Uat_Study
hang 2022-06-01 16:23:16 +08:00
parent 6f562252e4
commit aeeb70d8f0
1 changed files with 36 additions and 5 deletions

View File

@ -11,9 +11,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using EFCore.BulkExtensions;
using IRaCIS.Core.Domain.Share;
using System.Reflection;
namespace IRaCIS.Core.Infra.EFCore
{
@ -34,6 +32,14 @@ namespace IRaCIS.Core.Infra.EFCore
Task<bool> AnyAsync<T>(Expression<Func<T, bool>> filter, bool ignoreQueryFilters = false) where T : Entity;
/// <summary>
///不跟踪 查询单个实体不会出现NUll
/// </summary>
/// <param name="exp"></param>
/// <param name="ignoreQueryFilters"></param>
/// <returns></returns>
Task<T> FirstAsync<T>(Expression<Func<T, bool>> exp = null, bool isTracking = false, bool ignoreQueryFilters = false) where T : Entity;
Task<T> FirstOrDefaultAsync<T>(Expression<Func<T, bool>> exp = null, bool ignoreQueryFilters = false) where T : Entity;
Task<int> CountAsync<T>(Expression<Func<T, bool>> exp = null, bool ignoreQueryFilters = false) where T : Entity;
@ -257,6 +263,34 @@ namespace IRaCIS.Core.Infra.EFCore
return await query.CountAsync().ConfigureAwait(false);
}
public async Task<T> FirstAsync<T>(Expression<Func<T, bool>> exp = null, bool isTracking = false, bool ignoreQueryFilters = false) where T : Entity
{
var query = _dbContext.Set<T>().AsQueryable();
if (!isTracking)
{
query = query.AsNoTracking();
}
if (ignoreQueryFilters)
{
query = query.IgnoreQueryFilters();
}
var entity = await query.FirstOrDefaultAsync();
if (entity is null)
{
throw new QueryBusinessObjectNotExistException($"The query object {typeof(T).Name} does not exist in database, Please check the query parameters");
}
else
{
return entity;
}
}
public async Task<T> FirstOrDefaultAsync<T>(Expression<Func<T, bool>> exp = null, bool ignoreQueryFilters = false) where T : Entity
{
@ -367,9 +401,6 @@ namespace IRaCIS.Core.Infra.EFCore
return await SaveChangesAsync(autoSave);
}
#endregion
public async Task<bool> BatchDeleteAsync<T>(Expression<Func<T, bool>> deleteFilter) where T : Entity