namespace SharedDATA.Api
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore;
using SharedDATA.Context;
///
/// Defines the interfaces for generic repository.
/// 为通用存储库定义接口
///
/// The type of the entity.实体类型
public interface IRepository where TEntity : class
{
///
/// Changes the table name. This require the tables in the same database.
/// 更改表名。这需要相同数据库中的表
///
///
///
/// This only been used for supporting multiple tables in the same model. This require the tables in the same database.
/// 这只用于支持同一个模型中的多个表。这需要相同数据库中的表。
///
void ChangeTable(string table);
///
/// Gets the based on a predicate, orderby delegate and page information. This method default no-tracking query.
/// 基于谓词、orderby委托和页面信息获取。此方法默认无跟踪查询。
///
/// A function to test each element for a condition.用于测试条件的每个元素的函数
/// A function to order elements.对元素进行排序的函数
/// A function to include navigation properties 包含导航属性的函数
/// The index of page.起始页
/// The size of the page.页大小
/// True to disable changing tracking; otherwise, 禁用更改跟踪false. Default to true.
/// Ignore query filters 忽略查询过滤器
/// An that contains elements that satisfy the condition specified by 包含满足指定条件的元素.
/// This method default no-tracking query.
IPagedList GetPagedList(Expression> predicate = null,
Func, IOrderedQueryable> orderBy = null,
Func, IIncludableQueryable> include = null,
int pageIndex = 0,
int pageSize = 20,
bool disableTracking = true,
bool ignoreQueryFilters = false);
///
/// Gets the based on a predicate, orderby delegate and page information. This method default no-tracking query.
/// 基于谓词、orderby委托和页面信息获取。此方法默认无跟踪查询。
///
/// A function to test each element for a condition.用于测试条件的每个元素的函数
/// A function to order elements.对元素进行排序的函数
/// A function to include navigation properties 包含导航属性的函数
/// The index of page.起始页
/// The size of the page.页大小
/// True to disable changing tracking;禁用更改跟踪; otherwise, false. Default to true.
///
/// A to observe while waiting for the task to complete.
///
/// Ignore query filters 忽略查询过滤器
/// An that contains elements that satisfy the condition specified by .
/// This method default no-tracking query.此方法默认无跟踪查询
Task> GetPagedListAsync(Expression> predicate = null,
Func, IOrderedQueryable> orderBy = null,
Func, IIncludableQueryable> include = null,
int pageIndex = 0,
int pageSize = 20,
bool disableTracking = true,
CancellationToken cancellationToken = default(CancellationToken),
bool ignoreQueryFilters = false);
///
/// Gets the based on a predicate, orderby delegate and page information. This method default no-tracking query.
///
/// The selector for projection.
/// A function to test each element for a condition.
/// A function to order elements.
/// A function to include navigation properties
/// The index of page.
/// The size of the page.
/// True to disable changing tracking; otherwise, false. Default to true.
/// Ignore query filters
/// An that contains elements that satisfy the condition specified by .
/// This method default no-tracking query.
IPagedList GetPagedList(Expression> selector,
Expression> predicate = null,
Func, IOrderedQueryable> orderBy = null,
Func, IIncludableQueryable> include = null,
int pageIndex = 0,
int pageSize = 20,
bool disableTracking = true,
bool ignoreQueryFilters = false) where TResult : class;
///
/// Gets the based on a predicate, orderby delegate and page information. This method default no-tracking query.
///
/// The selector for projection.
/// A function to test each element for a condition.
/// A function to order elements.
/// A function to include navigation properties
/// The index of page.
/// The size of the page.
/// True to disable changing tracking; otherwise, false. Default to true.
///
/// A to observe while waiting for the task to complete.
///
/// Ignore query filters
/// An that contains elements that satisfy the condition specified by .
/// This method default no-tracking query.
Task> GetPagedListAsync(Expression> selector,
Expression> predicate = null,
Func, IOrderedQueryable> orderBy = null,
Func, IIncludableQueryable> include = null,
int pageIndex = 0,
int pageSize = 20,
bool disableTracking = true,
CancellationToken cancellationToken = default(CancellationToken),
bool ignoreQueryFilters = false) where TResult : class;
///
/// Gets the first or default entity based on a predicate, orderby delegate and include delegate. This method defaults to a read-only, no-tracking query.
///
/// A function to test each element for a condition.
/// A function to order elements.
/// A function to include navigation properties
/// true to disable changing tracking; otherwise, false. Default to true.
/// Ignore query filters
/// An that contains elements that satisfy the condition specified by .
/// This method defaults to a read-only, no-tracking query.
TEntity GetFirstOrDefault(Expression> predicate = null,
Func, IOrderedQueryable> orderBy = null,
Func, IIncludableQueryable> include = null,
bool disableTracking = true,
bool ignoreQueryFilters = false);
///
/// Gets the first or default entity based on a predicate, orderby delegate and include delegate. This method defaults to a read-only, no-tracking query.
///
/// The selector for projection.
/// A function to test each element for a condition.
/// A function to order elements.
/// A function to include navigation properties
/// true to disable changing tracking; otherwise, false. Default to true.
/// Ignore query filters
/// An that contains elements that satisfy the condition specified by .
/// This method defaults to a read-only, no-tracking query.
TResult GetFirstOrDefault(Expression> selector,
Expression> predicate = null,
Func, IOrderedQueryable> orderBy = null,
Func, IIncludableQueryable> include = null,
bool disableTracking = true,
bool ignoreQueryFilters = false);
///
/// Gets the first or default entity based on a predicate, orderby delegate and include delegate. This method defaults to a read-only, no-tracking query.
///
/// The selector for projection.
/// A function to test each element for a condition.
/// A function to order elements.
/// A function to include navigation properties
/// true to disable changing tracking; otherwise, false. Default to true.
/// Ignore query filters
/// An that contains elements that satisfy the condition specified by .
/// Ex: This method defaults to a read-only, no-tracking query.
Task GetFirstOrDefaultAsync(Expression> selector,
Expression> predicate = null,
Func, IOrderedQueryable> orderBy = null,
Func, IIncludableQueryable> include = null,
bool disableTracking = true,
bool ignoreQueryFilters = false);
///
/// Gets the first or default entity based on a predicate, orderby delegate and include delegate. This method defaults to a read-only, no-tracking query.
///
/// A function to test each element for a condition.
/// A function to order elements.
/// A function to include navigation properties
/// true to disable changing tracking; otherwise, false. Default to true.
/// Ignore query filters
/// An that contains elements that satisfy the condition specified by .
/// Ex: This method defaults to a read-only, no-tracking query.
Task GetFirstOrDefaultAsync(Expression> predicate = null,
Func, IOrderedQueryable> orderBy = null,
Func, IIncludableQueryable> include = null,
bool disableTracking = true,
bool ignoreQueryFilters = false);
///
/// Uses raw SQL queries to fetch the specified data.
///
/// The raw SQL.
/// The parameters.
/// An that contains elements that satisfy the condition specified by raw SQL.
IQueryable FromSql(string sql, params object[] parameters);
///
/// Finds an entity with the given primary key values. If found, is attached to the context and returned. If no entity is found, then null is returned.
///
/// The values of the primary key for the entity to be found.
/// The found entity or null.
TEntity Find(params object[] keyValues);
///
/// Finds an entity with the given primary key values. If found, is attached to the context and returned. If no entity is found, then null is returned.
///
/// The values of the primary key for the entity to be found.
/// A that represents the asynchronous find operation. The task result contains the found entity or null.
ValueTask FindAsync(params object[] keyValues);
///
/// Finds an entity with the given primary key values. If found, is attached to the context and returned. If no entity is found, then null is returned.
///
/// The values of the primary key for the entity to be found.
/// A to observe while waiting for the task to complete.
/// A that represents the asynchronous find operation. The task result contains the found entity or null.
ValueTask FindAsync(object[] keyValues, CancellationToken cancellationToken);
///
/// Gets all entities. This method is not recommended
///
/// The .
IQueryable GetAll();
///
/// Gets all entities. This method is not recommended
///
/// A function to test each element for a condition.
/// A function to order elements.
/// A function to include navigation properties
/// true to disable changing tracking; otherwise, false. Default to true.
/// Ignore query filters
/// An that contains elements that satisfy the condition specified by .
/// Ex: This method defaults to a read-only, no-tracking query.
IQueryable GetAll(Expression> predicate = null,
Func, IOrderedQueryable> orderBy = null,
Func, IIncludableQueryable> include = null,
bool disableTracking = true,
bool ignoreQueryFilters = false);
///
/// Gets all entities. This method is not recommended
///
/// The .
Task> GetAllAsync();
///
/// Gets all entities. This method is not recommended
///
/// A function to test each element for a condition.
/// A function to order elements.
/// A function to include navigation properties
/// true to disable changing tracking; otherwise, false. Default to true.
/// Ignore query filters
/// An that contains elements that satisfy the condition specified by .
/// Ex: This method defaults to a read-only, no-tracking query.
Task> GetAllAsync(Expression> predicate = null,
Func, IOrderedQueryable> orderBy = null,
Func, IIncludableQueryable> include = null,
bool disableTracking = true,
bool ignoreQueryFilters = false);
///
/// Gets the count based on a predicate.
///
///
///
int Count(Expression> predicate = null);
///
/// Gets async the count based on a predicate.
///
///
///
Task CountAsync(Expression> predicate = null);
///
/// Gets the long count based on a predicate.
///
///
///
long LongCount(Expression> predicate = null);
///
/// Gets async the long count based on a predicate.
///
///
///
Task LongCountAsync(Expression> predicate = null);
///
/// Gets the max based on a predicate.
///
///
/// ///
/// decimal
T Max(Expression> predicate = null, Expression> selector = null);
///
/// Gets the async max based on a predicate.
///
///
/// ///
/// decimal
Task MaxAsync(Expression> predicate = null, Expression> selector = null);
///
/// Gets the min based on a predicate.
///
///
///
/// decimal
T Min(Expression> predicate = null, Expression> selector = null);
///
/// Gets the async min based on a predicate.
///
///
///
/// decimal
Task MinAsync(Expression> predicate = null, Expression> selector = null);
///
/// Gets the average based on a predicate.
///
///
/// ///
/// decimal
decimal Average(Expression> predicate = null, Expression> selector = null);
///
/// Gets the async average based on a predicate.
///
///
/// ///
/// decimal
Task AverageAsync(Expression> predicate = null, Expression> selector = null);
///
/// Gets the sum based on a predicate.
///
///
/// ///
/// decimal
decimal Sum(Expression> predicate = null, Expression> selector = null);
///
/// Gets the async sum based on a predicate.
///
///
/// ///
/// decimal
Task SumAsync(Expression> predicate = null, Expression> selector = null);
///
/// Gets the Exists record based on a predicate.
///
///
///
bool Exists(Expression> selector = null);
///
/// Gets the Async Exists record based on a predicate.
///
///
///
Task ExistsAsync(Expression> selector = null);
///
/// Inserts a new entity synchronously.
///
/// The entity to insert.
TEntity Insert(TEntity entity);
///
/// Inserts a range of entities synchronously.
///
/// The entities to insert.
void Insert(params TEntity[] entities);
///
/// Inserts a range of entities synchronously.
///
/// The entities to insert.
void Insert(IEnumerable entities);
///
/// Inserts a new entity asynchronously.
///
/// The entity to insert.
/// A to observe while waiting for the task to complete.
/// A that represents the asynchronous insert operation.
ValueTask> InsertAsync(TEntity entity, CancellationToken cancellationToken = default(CancellationToken));
///
/// Inserts a range of entities asynchronously.
///
/// The entities to insert.
/// A that represents the asynchronous insert operation.
Task InsertAsync(params TEntity[] entities);
///
/// Inserts a range of entities asynchronously.
///
/// The entities to insert.
/// A to observe while waiting for the task to complete.
/// A that represents the asynchronous insert operation.
Task InsertAsync(IEnumerable entities, CancellationToken cancellationToken = default(CancellationToken));
///
/// Updates the specified entity.
///
/// The entity.
void Update(TEntity entity);
///
/// Updates the specified entities.
///
/// The entities.
void Update(params TEntity[] entities);
///
/// Updates the specified entities.
///
/// The entities.
void Update(IEnumerable entities);
///
/// Deletes the entity by the specified primary key.
///
/// The primary key value.
void Delete(object id);
///
/// Deletes the specified entity.
///
/// The entity to delete.
void Delete(TEntity entity);
///
/// Deletes the specified entities.
///
/// The entities.
void Delete(params TEntity[] entities);
///
/// Deletes the specified entities.
///
/// The entities.
void Delete(IEnumerable entities);
///
/// Change entity state for patch method on web api.
///
/// The entity.
/// /// The entity state.
void ChangeEntityState(TEntity entity, EntityState state);
}
}