Interface IRepository<TEntity, TPrimaryKey>
定义泛型仓储接口
public interface IRepository<TEntity, TPrimaryKey> : IRepository where TEntity : EntityBase<TPrimaryKey>
Type Parameters
TEntity
实体类型
TPrimaryKey
主键类型
- Extension Methods
Methods
Clear(bool)
删除实体
int Clear(bool autoSave = true)
Parameters
autoSave
bool是否立即执行保存
Returns
ClearAsync(bool)
删除实体
Task<int> ClearAsync(bool autoSave = true)
Parameters
autoSave
bool是否立即执行保存
Returns
Delete(TEntity, bool)
删除实体
int Delete(TEntity entity, bool autoSave = true)
Parameters
entity
TEntity要删除的实体
autoSave
bool是否立即执行保存
Returns
DeleteAsync(Expression<Func<TEntity, bool>>, bool)
根据条件删除实体
Task<int> DeleteAsync(Expression<Func<TEntity, bool>> where, bool autoSave = true)
Parameters
where
Expression<Func<TEntity, bool>>lambda表达式
autoSave
bool是否自动保存
Returns
DeleteAsync(TEntity, bool)
删除实体
Task<int> DeleteAsync(TEntity entity, bool autoSave = true)
Parameters
entity
TEntity要删除的实体
autoSave
bool是否立即执行保存
Returns
DeleteByID(TPrimaryKey, bool)
删除实体
int DeleteByID(TPrimaryKey id, bool autoSave = true)
Parameters
id
TPrimaryKey实体主键
autoSave
bool是否立即执行保存
Returns
DeleteByIDAsync(TPrimaryKey, bool)
删除实体
Task<int> DeleteByIDAsync(TPrimaryKey id, bool autoSave = true)
Parameters
id
TPrimaryKey实体主键
autoSave
bool是否立即执行保存
Returns
FirstOrDefaultAsync(Expression<Func<TEntity, bool>>)
根据lambda表达式条件获取单个实体
Task<TEntity> FirstOrDefaultAsync(Expression<Func<TEntity, bool>> predicate)
Parameters
predicate
Expression<Func<TEntity, bool>>lambda表达式条件
Returns
- Task<TEntity>
GetByIDAsync(TPrimaryKey)
根据主键获取实体
Task<TEntity> GetByIDAsync(TPrimaryKey id)
Parameters
id
TPrimaryKey实体主键
Returns
- Task<TEntity>
GetList()
获取实体集合
List<TEntity> GetList()
Returns
- List<TEntity>
GetList(Action<IQueryable<TEntity>>)
List<TEntity> GetList(Action<IQueryable<TEntity>> action)
Parameters
action
Action<IQueryable<TEntity>>
Returns
- List<TEntity>
GetList(Expression<Func<TEntity, bool>>)
根据lambda表达式条件获取实体集合
List<TEntity> GetList(Expression<Func<TEntity, bool>> predicate)
Parameters
predicate
Expression<Func<TEntity, bool>>lambda表达式条件
Returns
- List<TEntity>
GetList(params string[])
获取实体集合
List<TEntity> GetList(params string[] includes)
Parameters
includes
string[]
Returns
- List<TEntity>
GetListAsync()
获取实体集合
Task<List<TEntity>> GetListAsync()
Returns
GetListAsync(Expression<Func<TEntity, bool>>)
根据lambda表达式条件获取实体集合
Task<List<TEntity>> GetListAsync(Expression<Func<TEntity, bool>> predicate)
Parameters
predicate
Expression<Func<TEntity, bool>>lambda表达式条件
Returns
GetListAsync(params string[])
获取实体集合
Task<List<TEntity>> GetListAsync(params string[] includes)
Parameters
includes
string[]
Returns
Insert(TEntity, bool)
新增实体
int Insert(TEntity entity, bool autoSave = true)
Parameters
entity
TEntity实体
autoSave
bool是否立即执行保存
Returns
InsertAsync(TEntity, bool)
新增实体
Task<int> InsertAsync(TEntity entity, bool autoSave = true)
Parameters
entity
TEntity实体
autoSave
bool是否立即执行保存
Returns
InsertOrUpdateAsync(TEntity, bool)
新增或更新实体
Task<int> InsertOrUpdateAsync(TEntity entity, bool autoSave = true)
Parameters
entity
TEntity实体
autoSave
bool是否立即执行保存
Returns
InsertRangeAsync(params TEntity[])
新增实体
Task<int> InsertRangeAsync(params TEntity[] entity)
Parameters
entity
TEntity[]实体
Returns
LoadPageList(int, int, Expression<Func<TEntity, bool>>, Expression<Func<TEntity, object>>)
分页获取数据
Task<Tuple<List<TEntity>, int>> LoadPageList(int startPage, int pageSizet, Expression<Func<TEntity, bool>> where = null, Expression<Func<TEntity, object>> order = null)
Parameters
startPage
int起始页
pageSizet
intwhere
Expression<Func<TEntity, bool>>查询条件
order
Expression<Func<TEntity, object>>排序
Returns
Save()
保存
int Save()
Returns
SaveAsync()
保存
Task<int> SaveAsync()
Returns
Update(TEntity, bool)
更新实体
int Update(TEntity entity, bool autoSave = true)
Parameters
entity
TEntity实体
autoSave
bool是否立即执行保存
Returns
UpdateAsync(TEntity, bool)
更新实体
Task<int> UpdateAsync(TEntity entity, bool autoSave = true)
Parameters
entity
TEntity实体
autoSave
bool是否立即执行保存