|
|
|
@ -1,21 +1,12 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq.Expressions; |
|
|
|
using System.Threading; |
|
|
|
using System.Threading; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Volo.Abp.Domain.Entities; |
|
|
|
using Volo.Abp.Threading; |
|
|
|
|
|
|
|
namespace Volo.Abp.Domain.Repositories |
|
|
|
{ |
|
|
|
//public abstract class RepositoryBase<TEntity> : RepositoryBase<TEntity, Guid>, IRepository<TEntity>
|
|
|
|
// where TEntity : class, IEntity<Guid>
|
|
|
|
//{
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
public abstract class RepositoryBase<TEntity, TPrimaryKey> : IRepository<TEntity, TPrimaryKey> |
|
|
|
where TEntity : class, IEntity<TPrimaryKey> |
|
|
|
public abstract class RepositoryBase<TEntity> : IRepository<TEntity> |
|
|
|
where TEntity : class, IEntity |
|
|
|
{ |
|
|
|
public ICancellationTokenProvider CancellationTokenProvider { get; set; } |
|
|
|
|
|
|
|
@ -24,13 +15,37 @@ namespace Volo.Abp.Domain.Repositories |
|
|
|
CancellationTokenProvider = NullCancellationTokenProvider.Instance; |
|
|
|
} |
|
|
|
|
|
|
|
public abstract List<TEntity> GetList(); |
|
|
|
public abstract TEntity Insert(TEntity entity, bool autoSave = false); |
|
|
|
|
|
|
|
public virtual Task<List<TEntity>> GetListAsync(CancellationToken cancellationToken = default) |
|
|
|
public virtual Task<TEntity> InsertAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
return Task.FromResult(GetList()); |
|
|
|
return Task.FromResult(Insert(entity, autoSave)); |
|
|
|
} |
|
|
|
|
|
|
|
public abstract TEntity Update(TEntity entity); |
|
|
|
|
|
|
|
public virtual Task<TEntity> UpdateAsync(TEntity entity, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
return Task.FromResult(Update(entity)); |
|
|
|
} |
|
|
|
|
|
|
|
public abstract void Delete(TEntity entity); |
|
|
|
|
|
|
|
public virtual Task DeleteAsync(TEntity entity, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
Delete(entity); |
|
|
|
return Task.CompletedTask; |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual CancellationToken GetCancellationToken(CancellationToken prefferedValue = default) |
|
|
|
{ |
|
|
|
return CancellationTokenProvider.FallbackToProvider(prefferedValue); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public abstract class RepositoryBase<TEntity, TPrimaryKey> : RepositoryBase<TEntity>, IRepository<TEntity, TPrimaryKey> |
|
|
|
where TEntity : class, IEntity<TPrimaryKey> |
|
|
|
{ |
|
|
|
public virtual TEntity Get(TPrimaryKey id) |
|
|
|
{ |
|
|
|
var entity = Find(id); |
|
|
|
@ -55,28 +70,6 @@ namespace Volo.Abp.Domain.Repositories |
|
|
|
return Task.FromResult(Find(id)); |
|
|
|
} |
|
|
|
|
|
|
|
public abstract TEntity Insert(TEntity entity, bool autoSave = false); |
|
|
|
|
|
|
|
public virtual Task<TEntity> InsertAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
return Task.FromResult(Insert(entity, autoSave)); |
|
|
|
} |
|
|
|
|
|
|
|
public abstract TEntity Update(TEntity entity); |
|
|
|
|
|
|
|
public virtual Task<TEntity> UpdateAsync(TEntity entity, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
return Task.FromResult(Update(entity)); |
|
|
|
} |
|
|
|
|
|
|
|
public abstract void Delete(TEntity entity); |
|
|
|
|
|
|
|
public virtual Task DeleteAsync(TEntity entity, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
Delete(entity); |
|
|
|
return Task.CompletedTask; |
|
|
|
} |
|
|
|
|
|
|
|
public virtual void Delete(TPrimaryKey id) |
|
|
|
{ |
|
|
|
var entity = Find(id); |
|
|
|
@ -93,24 +86,5 @@ namespace Volo.Abp.Domain.Repositories |
|
|
|
Delete(id); |
|
|
|
return Task.CompletedTask; |
|
|
|
} |
|
|
|
|
|
|
|
public abstract long GetCount(); |
|
|
|
|
|
|
|
public virtual Task<long> GetCountAsync(CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
return Task.FromResult(GetCount()); |
|
|
|
} |
|
|
|
|
|
|
|
protected static Expression<Func<TEntity, bool>> CreateEqualityExpressionForId(TPrimaryKey id) |
|
|
|
{ |
|
|
|
var lambdaParam = Expression.Parameter(typeof(TEntity)); |
|
|
|
|
|
|
|
var lambdaBody = Expression.Equal( |
|
|
|
Expression.PropertyOrField(lambdaParam, "Id"), |
|
|
|
Expression.Constant(id, typeof(TPrimaryKey)) |
|
|
|
); |
|
|
|
|
|
|
|
return Expression.Lambda<Func<TEntity, bool>>(lambdaBody, lambdaParam); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|