using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
namespace FreeSql
{
public interface IBaseRepository : IDisposable
{
Type EntityType { get; }
IUnitOfWork UnitOfWork { get; set; }
IFreeSql Orm { get; }
///
/// 动态Type,在使用 Repository<object> 后使用本方法,指定实体类型
///
///
///
void AsType(Type entityType);
///
/// 分表规则,参数:旧表名;返回:新表名 https://github.com/2881099/FreeSql/wiki/Repository
///
///
void AsTable(Func rule);
///
/// 设置 DbContext 选项
///
DbContextOptions DbContextOptions { get; set; }
}
public interface IBaseRepository : IBaseRepository
where TEntity : class
{
IDataFilter DataFilter { get; }
ISelect Select { get; }
ISelect Where(Expression> exp);
ISelect WhereIf(bool condition, Expression> exp);
TEntity Insert(TEntity entity);
List Insert(IEnumerable entitys);
///
/// 清空状态数据
///
void FlushState();
///
/// 附加实体,可用于不查询就更新或删除
///
///
void Attach(TEntity entity);
void Attach(IEnumerable entity);
///
/// 附加实体,并且只附加主键值,可用于不更新属性值为null或默认值的字段
///
///
IBaseRepository AttachOnlyPrimary(TEntity data);
///
/// 比较实体,计算出值发生变化的属性,以及属性变化的前后值
///
/// 最新的实体对象,它将与附加实体的状态对比
/// key: 属性名, value: [旧值, 新值]
Dictionary CompareState(TEntity newdata);
int Update(TEntity entity);
int Update(IEnumerable entitys);
TEntity InsertOrUpdate(TEntity entity);
///
/// 保存实体的指定 ManyToMany/OneToMany 导航属性(完整对比)
/// 场景:在关闭级联保存功能之后,手工使用本方法
/// 例子:保存商品的 OneToMany 集合属性,SaveMany(goods, "Skus")
/// 当 goods.Skus 为空(非null)时,会删除表中已存在的所有数据
/// 当 goods.Skus 不为空(非null)时,添加/更新后,删除表中不存在 Skus 集合属性的所有记录
///
/// 实体对象
/// 属性名
void SaveMany(TEntity entity, string propertyName);
IUpdate UpdateDiy { get; }
int Delete(TEntity entity);
int Delete(IEnumerable entitys);
int Delete(Expression> predicate);
///
/// 根据设置的 OneToOne/OneToMany/ManyToMany 导航属性,级联查询所有的数据库记录,删除并返回它们
///
///
///
List