Added repository base classes.

pull/81/head
Halil İbrahim Kalkan 9 years ago
parent 50f2eae288
commit 8a9ba18b48

@ -6,7 +6,8 @@ namespace Volo.Abp.Domain.Repositories
{
//TODO: Didn't get all members from ABP 1.x
public interface IRepository<TEntity, TPrimaryKey> : IRepositoryMarker where TEntity : class, IEntity<TPrimaryKey>
public interface IRepository<TEntity, TPrimaryKey> : IRepositoryMarker
where TEntity : class, IEntity<TPrimaryKey>
{
/// <summary>
/// Used to get all entities.

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Volo.Abp.Domain.Entities;
namespace Volo.Abp.Domain.Repositories
{
public abstract class QueryableRepositoryBase<TEntity, TPrimaryKey> : RepositoryBase<TEntity, TPrimaryKey>, IQueryableRepository<TEntity, TPrimaryKey>
where TEntity : class, IEntity<TPrimaryKey>
{
public abstract IQueryable<TEntity> GetAll();
public abstract List<TEntity> GetAllList(Expression<Func<TEntity, bool>> predicate);
public virtual Task<List<TEntity>> GetAllListAsync(Expression<Func<TEntity, bool>> predicate)
{
return Task.FromResult(GetAllList(predicate));
}
public abstract TEntity FirstOrDefault(Expression<Func<TEntity, bool>> predicate);
public virtual Task<TEntity> FirstOrDefaultAsync(Expression<Func<TEntity, bool>> predicate)
{
return Task.FromResult(FirstOrDefault(predicate));
}
public abstract void Delete(Expression<Func<TEntity, bool>> predicate);
public virtual Task DeleteAsync(Expression<Func<TEntity, bool>> predicate)
{
Delete(predicate);
return Task.CompletedTask;
}
public abstract int Count(Expression<Func<TEntity, bool>> predicate);
public virtual Task<int> CountAsync(Expression<Func<TEntity, bool>> predicate)
{
return Task.FromResult(Count(predicate));
}
}
}

@ -0,0 +1,78 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Domain.Entities;
namespace Volo.Abp.Domain.Repositories
{
public abstract class RepositoryBase<TEntity, TPrimaryKey> : IRepository<TEntity, TPrimaryKey>
where TEntity : class, IEntity<TPrimaryKey>
{
public abstract List<TEntity> GetAllList();
public virtual Task<List<TEntity>> GetAllListAsync()
{
return Task.FromResult(GetAllList());
}
public abstract TEntity Get(TPrimaryKey id);
public virtual Task<TEntity> GetAsync(TPrimaryKey id)
{
return Task.FromResult(Get(id));
}
public abstract TEntity FirstOrDefault(TPrimaryKey id);
public virtual Task<TEntity> FirstOrDefaultAsync(TPrimaryKey id)
{
return Task.FromResult(FirstOrDefault(id));
}
public abstract TEntity Insert(TEntity entity);
public virtual Task<TEntity> InsertAsync(TEntity entity)
{
return Task.FromResult(Insert(entity));
}
public virtual TPrimaryKey InsertAndGetId(TEntity entity)
{
return Insert(entity).Id;
}
public virtual Task<TPrimaryKey> InsertAndGetIdAsync(TEntity entity)
{
return Task.FromResult(InsertAndGetId(entity));
}
public abstract TEntity Update(TEntity entity);
public virtual Task<TEntity> UpdateAsync(TEntity entity)
{
return Task.FromResult(Update(entity));
}
public abstract void Delete(TEntity entity);
public virtual Task DeleteAsync(TEntity entity)
{
Delete(entity);
return Task.CompletedTask;
}
public abstract void Delete(TPrimaryKey id);
public virtual Task DeleteAsync(TPrimaryKey id)
{
Delete(id);
return Task.CompletedTask;
}
public abstract int Count();
public virtual Task<int> CountAsync()
{
return Task.FromResult(Count());
}
}
}
Loading…
Cancel
Save