增加Global Using
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-09-20 10:19:08 +08:00
parent 115017197b
commit fc30cb39ee
408 changed files with 11031 additions and 12556 deletions
@@ -1,13 +1,5 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Query;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore.Query;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace IRaCIS.Core.Infra.EFCore
{
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using IRaCIS.Core.Domain.Models;
using IRaCIS.Core.Domain.Models;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Query;
@@ -95,7 +89,7 @@ namespace IRaCIS.Core.Infra.EFCore
/// <param name="exp"></param>
/// <param name="ignoreQueryFilters"></param>
/// <returns></returns>
Task<TEntity> FirstAsync(Expression<Func<TEntity, bool>> exp = null, bool isTracking = false,bool ignoreQueryFilters = false);
Task<TEntity> FirstAsync(Expression<Func<TEntity, bool>> exp = null, bool isTracking = false, bool ignoreQueryFilters = false);
/// <summary>
///跟踪 查询单个实体,会出现NUll 可以直接在实体对属性进行修改,然后save
@@ -1,18 +1,12 @@
using AutoMapper;
using IRaCIS.Core.Domain.Models;
//using AutoMapper.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
namespace IRaCIS.Core.Infra.EFCore
{
public interface IQueryRepository<TEntity, TKey> where TEntity : Entity
{
IQueryable<TResult> Select<TResult>( Expression<Func<TEntity, TResult>> selector);
IQueryable<TResult> Select<TResult>(Expression<Func<TEntity, TResult>> selector);
ValueTask<TEntity> FindAsync(TKey id, CancellationToken cancellationToken = default);
@@ -24,7 +18,7 @@ namespace IRaCIS.Core.Infra.EFCore
{
TEntity ImageFind(Guid id, Type type);
IQueryable<TEntity> Where(Expression<Func<TEntity, bool>> exp = null, bool isTraking = false, bool ignoreQueryFilters = false);
IQueryable<TEntity> AsQueryable( bool ignoreQueryFilters = false);
IQueryable<TEntity> AsQueryable(bool ignoreQueryFilters = false);
IQueryable<TEntity> WhereIf(bool condition, Expression<Func<TEntity, bool>> filter);
IQueryable<TDestination> ProjectTo<TDestination>(IConfigurationProvider configuration, params Expression<Func<TDestination, object>>[] membersToExpand);
@@ -1,17 +1,8 @@
using AutoMapper.Internal;
using EFCore.BulkExtensions;
using IRaCIS.Core.Domain.Models;
using IRaCIS.Core.Domain.Models;
using IRaCIS.Core.Infrastructure;
using IRaCIS.Core.Infrastructure.Extention;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Query;
using SharpCompress.Factories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Threading.Tasks;
namespace IRaCIS.Core.Infra.EFCore
{
@@ -235,7 +226,7 @@ namespace IRaCIS.Core.Infra.EFCore
public static async Task<bool> ExecuteUpdateAsync<T>(this IRaCISDBContext _dbContext, Expression<Func<T, bool>> where, Expression<Func<SetPropertyCalls<T>, SetPropertyCalls<T>>> setPropertyCalls) where T : Entity
{
return await _dbContext.Set<T>().Where(where).ExecuteUpdateAsync<T>(setPropertyCalls)>0;
return await _dbContext.Set<T>().Where(where).ExecuteUpdateAsync<T>(setPropertyCalls) > 0;
}
@@ -2,16 +2,10 @@
using AutoMapper;
using IRaCIS.Core.Domain.Models;
using IRaCIS.Core.Domain.Share;
using IRaCIS.Core.Infrastructure;
using IRaCIS.Core.Infrastructure.Extention;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using IRaCIS.Core.Domain.Share;
using Microsoft.Extensions.Localization;
namespace IRaCIS.Core.Infra.EFCore
@@ -176,7 +170,7 @@ namespace IRaCIS.Core.Infra.EFCore
if (dbEntity == null)
{
throw new BusinessValidationFailedException(_localizer["Repository_UpdateError"]);
}
@@ -378,7 +372,7 @@ namespace IRaCIS.Core.Infra.EFCore
{
_dbContext.Set<T>().UpdateRange(entities);
await SaveChangesAsync(autoSave);
await SaveChangesAsync(autoSave);
}
@@ -428,9 +422,9 @@ namespace IRaCIS.Core.Infra.EFCore
{
if (updateFilter == null)
{
throw new ArgumentException("The update filter condition cannot be empty", nameof(updateFilter));
throw new ArgumentException("The update filter condition cannot be empty", nameof(updateFilter));
}
var query = ignoreQueryFilter ? _dbContext.Set<T>().AsNoTracking().IgnoreQueryFilters() : _dbContext.Set<T>().AsNoTracking();
@@ -446,7 +440,7 @@ namespace IRaCIS.Core.Infra.EFCore
public async Task<bool> UpdateAsync<T>(T waitModifyEntity, Expression<Func<T, T>> updateFactory, bool autoSave = false) where T : Entity
{
_dbContext.EntityModifyPartialFiled(waitModifyEntity, updateFactory);
return await SaveChangesAsync(autoSave);
@@ -1,20 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using AutoMapper;
using IRaCIS.Core.Domain.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using AutoMapper;
using AutoMapper.QueryableExtensions;
using IRaCIS.Core.Domain.Models;
using IRaCIS.Core.Domain.Share;
using IRaCIS.Core.Infrastructure;
using IRaCIS.Core.Infrastructure.Extention;
using Microsoft.Extensions.Localization;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.Extensions.Localization;
namespace IRaCIS.Core.Infra.EFCore
{
@@ -153,14 +145,14 @@ namespace IRaCIS.Core.Infra.EFCore
/// <summary>EF跟踪方式 先查询出来,再更新部分字段 当在同一个事务里面需要更新同一个实体两次,请使用该方法,否则会因为重复跟踪同一个实体报错 (稽查的时候需要完整的实体信息)</summary>
public async Task<TEntity> UpdatePartialFromQueryAsync(Guid id, Expression<Func<TEntity, TEntity>> updateFactory,
bool autoSave = false, CancellationToken cancellationToken = default)
bool autoSave = false, CancellationToken cancellationToken = default)
{
//var query = ignoreQueryFilter ? _dbSet.AsNoTracking().IgnoreQueryFilters() : _dbSet.AsNoTracking();
//不跟踪 查询出来的实体就是Detached
var searchEntity = await _dbSet.FindAsync( id);
var searchEntity = await _dbSet.FindAsync(id);
if (searchEntity == null)
{
@@ -275,7 +267,7 @@ namespace IRaCIS.Core.Infra.EFCore
Expression<Func<TEntity, TEntity>> updateFactory)
{
return await _dbContext.BatchUpdateNoTrackingAsync(where, updateFactory,_userInfo.Id);
return await _dbContext.BatchUpdateNoTrackingAsync(where, updateFactory, _userInfo.Id);
}
@@ -477,7 +469,7 @@ namespace IRaCIS.Core.Infra.EFCore
}
public bool Any(Expression<Func<TEntity, bool>> exp, bool ignoreQueryFilters = false)
public bool Any(Expression<Func<TEntity, bool>> exp, bool ignoreQueryFilters = false)
{
var query = _dbSet.AsQueryable();
@@ -486,7 +478,7 @@ namespace IRaCIS.Core.Infra.EFCore
query = query.IgnoreQueryFilters();
}
return query.AsNoTracking().Any(exp);
return query.AsNoTracking().Any(exp);
}
public async Task<int> CountAsync(Expression<Func<TEntity, bool>> whereLambda = null, bool ignoreQueryFilters = false)