修改仓储
							parent
							
								
									6f562252e4
								
							
						
					
					
						commit
						aeeb70d8f0
					
				|  | @ -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 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue