提交
This commit is contained in:
@@ -89,6 +89,8 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||
|
||||
Task<TEntity> FirstOrDefaultAsync(Expression<Func<TEntity, bool>> exp = null, bool ignoreQueryFilters = false);
|
||||
|
||||
Task<TEntity> FirstOrDefaultNoTrackingAsync(Expression<Func<TEntity, bool>> exp = null, bool ignoreQueryFilters = false);
|
||||
|
||||
Task<bool> AnyAsync(Expression<Func<TEntity, bool>> exp, bool ignoreQueryFilters = false);
|
||||
|
||||
Task<TResult> MaxAsync<TResult>(Expression<Func<TEntity, TResult>> selector);
|
||||
|
||||
@@ -1412,6 +1412,32 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 不跟踪
|
||||
/// </summary>
|
||||
/// <param name="exp"></param>
|
||||
/// <param name="ignoreQueryFilters"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<TEntity> FirstOrDefaultNoTrackingAsync(Expression<Func<TEntity, bool>> exp = null, bool ignoreQueryFilters = false)
|
||||
{
|
||||
|
||||
var query = _dbSet.AsNoTracking().AsQueryable();
|
||||
|
||||
if (ignoreQueryFilters)
|
||||
{
|
||||
query = query.IgnoreQueryFilters();
|
||||
}
|
||||
|
||||
|
||||
if (exp != null)
|
||||
{
|
||||
query = query.Where(exp);
|
||||
}
|
||||
|
||||
return await query.AsNoTracking().FirstOrDefaultAsync().ConfigureAwait(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user