using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Expressions; using MyCode.Project.Infrastructure.Search; using MyCode.Project.Infrastructure.Common; using System.Data.SqlClient; using SqlSugar; using System.Data; namespace MyCode.Project.Domain.Repositories { public interface IRepository where TEntity : class { #region 事务处理 void BeginTran(); void CommitTran(); void RollbackTran(); #endregion /// /// 根据表达式得到列表 /// /// 条件 /// List SelectList(Expression> whereExpression=null); /// /// 查询分页 /// 例子 "select * from table where id=@id and name=@name",new {id=1,name="a"} /// PageResult SelectListPage(string sql, int pageIndex, int pageSize, string order, object parameters = null) where T : class, new(); /// /// 查询分页 /// PageResult SelectListPage(string sql, SearchCondition condition, int pageIndex, int pageSize, string order) where T : class, new(); /// /// 执行命令 /// /// SQL条件 /// 参数,可以直接用new{id=1} /// int ExecuteSqlCommand(string sql, object parameters = null); /// /// 返回单条记录 /// /// /// TEntity SelectFirst(Expression> whereExpression); /// /// 用SQL返回单条记录 /// 例子 "select * from table where id=@id and name=@name",new {id=1,name="a"} /// T SelectFirst(string sql, object parameters = null); /// /// 用SQL返回多条记录 /// 例子 "select * from table where id=@id and name=@name",new {id=1,name="a"} /// List SelectList(string sql, object parameters = null); /// /// 用SQL + 条件返回多条记录 /// /// /// SQL语句 /// SearchCondition对象 /// List SelectList(string strSql, SearchCondition where); /// /// 根据主键返回的列表 /// /// 一组主键ID /// List SelectList(List ids); /// /// 得到数量 /// /// 条件 /// int Count(Expression> predicate); /// /// 添加 /// /// 实体 /// null使用默认表名。不为NULL,适用于分表情况 void Add(TEntity instance, string tablename = null); /// /// 批量添加实体 /// /// 实体集合 /// null使用默认表名。不为NULL,适用于分表情况 void Add(List entities, string tablename = null); /// /// 单个的修改 /// /// void Update(TEntity instance); /// /// 修改一组对象 /// /// void Update(List updateObjs); /// /// 批量修改,只修改某些字段 /// /// /// void Update(List updateObjs, Expression> columns); /// /// 按字段批量修改一组对象 /// /// 一组对象 /// 要修改的列 void Update(IEnumerable updateObjs, Expression> columns); /// /// 根据表达式是否存在 /// /// /// bool IsExist(Expression> whereExpression); /// /// 批量修改的方法 /// /// 修改的动态对象 /// 要修改的列 //void Update(dynamic updateDynamicObject, Expression> columns); //void Update(dynamic updateDynamicObject); /// /// 按字段修改,满足条件的数据,批量修改的补充。 /// 例子:Update(it => new WorkProcess { Remark = "测试批量修改",SystemType = 0 },p => p.WorkProcessId ==Guid.Parse("7BDDBBD3-B1CD-4C25-93BA-D7BF22032108")); /// /// 要修改的列 /// 要修改的条件 int Update(Expression> columns, Expression> whereExpression); /// /// 根据表达式删除 /// /// int Delete(Expression> whereExpression); /// /// 根据ID删除 /// /// void DeleteByIds(dynamic[] ids); /// /// 得到一个更加灵活的查询对象 /// /// ISugarQueryable Queryable(); /// /// 用SQL返回单条记录 /// /// /// SQL语句 /// 条件Condition /// T SelectFirst(string sql, SearchCondition searchCondition); /// /// 得到Table表数据 /// /// /// /// DataTable SelectTable(string sql, object parameters = null); } }