You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Haoliang.Data.Repositories
{
public interface IRepository<T> where T : class
{
Task<T> GetByIdAsync(int id);
Task<IEnumerable<T>> GetAllAsync();
Task<IEnumerable<T>> FindAsync(System.Linq.Expressions.Expression<Func<T, bool>> predicate);
Task<T> SingleOrDefaultAsync(System.Linq.Expressions.Expression<Func<T, bool>> predicate);
Task AddAsync(T entity);
Task AddRangeAsync(IEnumerable<T> entities);
void Update(T entity);
void Remove(T entity);
void RemoveRange(IEnumerable<T> entities);
Task<int> CountAsync(System.Linq.Expressions.Expression<Func<T, bool>> predicate = null);
Task<bool> ExistsAsync(System.Linq.Expressions.Expression<Func<T, bool>> predicate);
Task SaveAsync();
}
public interface IReadRepository<T> where T : class
{
Task<T> GetByIdAsync(int id);
Task<IEnumerable<T>> GetAllAsync();
Task<IEnumerable<T>> FindAsync(System.Linq.Expressions.Expression<Func<T, bool>> predicate);
Task<T> SingleOrDefaultAsync(System.Linq.Expressions.Expression<Func<T, bool>> predicate);
Task<int> CountAsync(System.Linq.Expressions.Expression<Func<T, bool>> predicate = null);
Task<bool> ExistsAsync(System.Linq.Expressions.Expression<Func<T, bool>> predicate);
}
public interface IWriteRepository<T> where T : class
{
Task AddAsync(T entity);
Task AddRangeAsync(IEnumerable<T> entities);
void Update(T entity);
void Remove(T entity);
void RemoveRange(IEnumerable<T> entities);
Task<int> SaveAsync();
}
}