using Microsoft.Data.SqlClient; using Microsoft.EntityFrameworkCore.Query; using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; using SqlSugar; using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Linq.Expressions; using System.Threading.Tasks; using LM.Core.DbContext; using LM.Core.Enums; using LM.Core.Utilities; using LM.Entity.SystemModels; namespace LM.Core.BaseProvider { public interface IRepository where TEntity : BaseEntity { VOLContext VOLContext { get; } /// /// EF DBContext /// ISqlSugarClient DbContext { get; } ISqlSugarClient SqlSugarClient { get; } /// /// 执行事务。将在执行的方法带入Action /// /// /// WebResponseContent DbContextBeginTransaction(Func action); /// /// /// /// 查询条件 /// 是否过滤逻辑删除的数据,默认过 /// List Find(Expression> where, bool filterDeleted = true); /// /// /// /// /// 排序字段,数据格式如: /// orderBy = x => new Dictionary() { /// { x.BalconyName,QueryOrderBy.Asc}, /// { x.TranCorpCode1,QueryOrderBy.Desc} /// }; /// 是否过滤逻辑删除的数据,默认过 /// /// TEntity FindFirst(Expression> predicate, bool filterDeleted = true); /// /// if判断查询 /// /// 查询示例,value不为null时参与条件查询 /// string value = null; /// repository.WhereIF(value!=null,x=>x.Creator==value); /// /// /// ISugarQueryable WhereIF(bool checkCondition, Expression> predicate); /// /// if判断查询 /// /// 查询示例,value不为null时参与条件查询 /// string value = null; /// repository.WhereIF(value!=null,x=>x.Creator==value); /// /// /// ISugarQueryable WhereIF(bool checkCondition, Expression> predicate) where T : class; /// /// /// /// where条件 /// 排序字段,数据格式如: /// orderBy = x => new Dictionary() { /// { x.BalconyName,QueryOrderBy.Asc}, /// { x.TranCorpCode1,QueryOrderBy.Desc} /// }; /// /// ISugarQueryable FindAsIQueryable(Expression> predicate, Expression>> orderBy = null); /// /// 通过条件查询数据 /// /// /// 查询条件 /// 返回类型如:Find(x => x.UserName == loginInfo.userName, p => new { uname = p.UserName }); /// List Find(Expression> predicate, Expression> selector, bool filterDeleted = true); /// /// 根据条件,返回查询的类 /// /// /// /// 是否过滤逻辑删除的数据,默认过 /// List Find(Expression> predicate, bool filterDeleted = true) where TFind : class; /// /// /// /// /// /// 是否过滤逻辑删除的数据,默认过 /// Task FindAsyncFirst(Expression> predicate, bool filterDeleted = true) where TFind : class; /// /// /// /// ///是否过滤逻辑删除的数据,默认过 /// Task FindAsyncFirst(Expression> predicate, bool filterDeleted = true); /// /// /// /// /// /// 是否过滤逻辑删除的数据,默认过 /// Task> FindAsync(Expression> predicate, bool filterDeleted = true) where TFind : class; /// /// /// /// ///是否过滤逻辑删除的数据,默认过 /// Task FindFirstAsync(Expression> predicate, bool filterDeleted = true); /// /// /// /// /// 是否过滤逻辑删除的数据,默认过 /// Task> FindAsync(Expression> predicate, bool filterDeleted = true); /// /// /// /// /// /// ///是否过滤逻辑删除的数据,默认过 /// Task> FindAsync(Expression> predicate, Expression> selector, bool filterDeleted = true); /// /// /// /// /// /// /// 是否过滤逻辑删除的数据,默认过 /// Task FindFirstAsync(Expression> predicate, Expression> selector, bool filterDeleted = true); /// /// /// /// /// 是否过滤逻辑删除的数据,默认过 /// Task ExistsAsync(Expression> predicate, bool filterDeleted = true); /// /// /// /// /// 是否过滤逻辑删除的数据,默认过 /// bool Exists(Expression> predicate, bool filterDeleted = true); /// /// /// /// /// /// 是否过滤逻辑删除的数据,默认过 /// bool Exists(Expression> predicate, bool filterDeleted = true) where TExists : class; /// /// /// /// /// /// 是否过滤逻辑删除的数据,默认过 /// Task ExistsAsync(Expression> predicate, bool filterDeleted = true) where TExists : class; ISugarQueryable Include(Expression> incluedProperty); ISugarQueryable IQueryablePage(int pageIndex, int pagesize, out int rowcount, Expression> predicate, Expression>> orderBy, bool returnRowCount = true) where TFind : class; ISugarQueryable IQueryablePage(ISugarQueryable queryable, int pageIndex, int pagesize, out int rowcount, Dictionary orderBy, bool returnRowCount = true); /// /// /// /// /// 指定更新字段:x=>new {x.Name,x.Enable} /// 是否保存 /// int Update(TEntity entity, Expression> properties, bool saveChanges = false); /// /// /// /// /// 指定更新字段:x=>new {x.Name,x.Enable} /// 是否保存 /// int Update(TSource entity, Expression> properties, bool saveChanges = false) where TSource : class, new(); int Update(TSource entity, bool saveChanges = false) where TSource : class, new(); int Update(TSource entity, string[] properties, bool saveChanges = false) where TSource : class, new(); int UpdateRange(IEnumerable entities, bool saveChanges = false) where TSource : class, new(); /// /// /// /// /// 指定更新字段:x=>new {x.Name,x.Enable} /// 是否保存 /// int UpdateRange(IEnumerable models, Expression> properties, bool saveChanges = false) where TSource : class, new(); int UpdateRange(IEnumerable entities, string[] properties, bool saveChanges = false) where TSource : class, new(); /// ///修改时同时对明细的添加、删除、修改 /// /// /// 是否修改明细 /// 是否删除明细不存在的数据 /// 主表指定修改字段 /// 明细指定修改字段 /// 是否保存 /// WebResponseContent UpdateRange(TEntity entity, bool updateDetail = false, bool delNotExist = false, Expression> updateMainFields = null, Expression> updateDetailFields = null, bool saveChange = false) where Detail : class, new(); void Delete(TEntity model, bool saveChanges = false); void Delete(T model, bool saveChanges = false) where T : class, new(); /// /// /// /// /// 是否将子表的数据也删除 /// 是否执行保存数据库 /// int DeleteWithKeys(object[] keys, bool saveChange = true); /// /// 写入数据并设置自增 /// /// void AddWithSetIdentity(TEntity entity); void AddWithSetIdentity(T entity) where T : class, new(); void Add(TEntity entities, bool SaveChanges = false); void Add(T entities, bool saveChanges = false) where T : class, new(); // void AddRange(IEnumerable entities, bool SaveChanges = false); void AddRange(List entities, bool saveChanges = false) where T : class, new(); int SaveChanges(); Task SaveChangesAsync(); int ExecuteSqlCommand(string sql, params SugarParameter[] SugarParameters); List FromSql(string sql, params SugarParameter[] SugarParameters); /// /// 执行sql /// 使用方式 FormattableString sql=$"select * from xx where name ={xx} and pwd={xx1} ", /// FromSqlInterpolated内部处理sql注入的问题,直接在{xx}写对应的值即可 /// 注意:sql必须 select * 返回所有TEntity字段, /// /// /// // ISugarQueryable FromSqlInterpolated([System.Diagnostics.CodeAnalysis.NotNull] FormattableString sql); /// /// 取消上下文跟踪(2021.08.22) /// 更新报错时,请调用此方法:The instance of entity type 'XXX' cannot be tracked because another instance with the same key value for {'XX'} is already being tracked. /// /// void Detached(TEntity entity); void DetachedRange(IEnumerable entities); } }