using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; namespace SqlSugar { public partial class SimpleClient { protected SqlSugarClient Context { get; set; } public SqlSugarClient FullClient { get { return this.Context; } } private SimpleClient() { } public SimpleClient(SqlSugarClient context) { this.Context = context; } public T GetById(dynamic id) where T : class, new() { return Context.Queryable().InSingle(id); } public List GetList() where T : class, new() { return Context.Queryable().ToList(); } public T GetSingle(Expression> whereExpression) where T : class, new() { return Context.Queryable().Single(whereExpression); } public List GetList(Expression> whereExpression) where T : class, new() { return Context.Queryable().Where(whereExpression).ToList(); } public List GetPageList(Expression> whereExpression, PageModel page) where T : class, new() { int count = 0; var result = Context.Queryable().Where(whereExpression).ToPageList(page.PageIndex, page.PageSize, ref count); page.PageCount = count; return result; } public List GetPageList(Expression> whereExpression, PageModel page, Expression> orderByExpression = null, OrderByType orderByType = OrderByType.Asc) where T : class, new() { int count = 0; var result = Context.Queryable().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(whereExpression).ToPageList(page.PageIndex, page.PageSize, ref count); page.PageCount = count; return result; } public List GetPageList(List conditionalList, PageModel page) where T : class, new() { int count = 0; var result = Context.Queryable().Where(conditionalList).ToPageList(page.PageIndex, page.PageSize, ref count); page.PageCount = count; return result; } public List GetPageList(List conditionalList, PageModel page, Expression> orderByExpression = null, OrderByType orderByType = OrderByType.Asc) where T : class, new() { int count = 0; var result = Context.Queryable().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(conditionalList).ToPageList(page.PageIndex, page.PageSize, ref count); page.PageCount = count; return result; } public bool IsAny(Expression> whereExpression) where T : class, new() { return Context.Queryable().Where(whereExpression).Any(); } public bool Insert(T insertObj) where T : class, new() { return this.Context.Insertable(insertObj).ExecuteCommand() > 0; } public int InsertReturnIdentity(T insertObj) where T : class, new() { return this.Context.Insertable(insertObj).ExecuteReturnIdentity(); } public bool InsertRange(T[] insertObjs) where T : class, new() { return this.Context.Insertable(insertObjs).ExecuteCommand() > 0; } public bool InsertRange(List insertObjs) where T : class, new() { return this.Context.Insertable(insertObjs).ExecuteCommand() > 0; } public bool Update(T updateObj) where T : class, new() { return this.Context.Updateable(updateObj).ExecuteCommand() > 0; } public bool UpdateRange(T[] updateObjs) where T : class, new() { return this.Context.Updateable(updateObjs).ExecuteCommand() > 0; } public bool UpdateRange(List updateObjs) where T : class, new() { return this.Context.Updateable(updateObjs).ExecuteCommand() > 0; } public bool Update(Expression> columns, Expression> whereExpression) where T : class, new() { return this.Context.Updateable().UpdateColumns(columns).Where(whereExpression).ExecuteCommand() > 0; } public bool Delete(T deleteObj) where T : class, new() { return this.Context.Deleteable().Where(deleteObj).ExecuteCommand() > 0; } public bool Delete(Expression> whereExpression) where T : class, new() { return this.Context.Deleteable().Where(whereExpression).ExecuteCommand() > 0; } public bool DeleteById(dynamic id) where T : class, new() { return this.Context.Deleteable().In(id).ExecuteCommand() > 0; } public bool DeleteByIds(dynamic[] ids) where T : class, new() { return this.Context.Deleteable().In(ids).ExecuteCommand() > 0; } } public partial class SimpleClient where T : class, new() { protected SqlSugarClient Context { get; set; } public SqlSugarClient FullClient { get { return this.Context; } } private SimpleClient() { } public SimpleClient(SqlSugarClient context) { this.Context = context; } public ISugarQueryable AsQueryable() { return Context.Queryable(); } public IInsertable AsInsertable(T insertObj) { return Context.Insertable(insertObj); } public IInsertable AsInsertable(T[] insertObjs) { return Context.Insertable(insertObjs); } public IInsertable AsInsertable(List insertObjs) { return Context.Insertable(insertObjs); } public IUpdateable AsUpdateable(T updateObj) { return Context.Updateable(updateObj); } public IUpdateable AsUpdateable(T[] updateObjs) { return Context.Updateable(updateObjs); } public IUpdateable AsUpdateable(List updateObjs) { return Context.Updateable(updateObjs); } public IDeleteable AsDeleteable() { return Context.Deleteable(); } public T GetById(dynamic id) { return Context.Queryable().InSingle(id); } public List GetList() { return Context.Queryable().ToList(); } public List GetList(Expression> whereExpression) { return Context.Queryable().Where(whereExpression).ToList(); } public T GetSingle(Expression> whereExpression) { return Context.Queryable().Single(whereExpression); } public List GetPageList(Expression> whereExpression, PageModel page) { int count = 0; var result = Context.Queryable().Where(whereExpression).ToPageList(page.PageIndex, page.PageSize, ref count); page.PageCount = count; return result; } public List GetPageList(Expression> whereExpression, PageModel page, Expression> orderByExpression = null, OrderByType orderByType = OrderByType.Asc) { int count = 0; var result = Context.Queryable().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(whereExpression).ToPageList(page.PageIndex, page.PageSize, ref count); page.PageCount = count; return result; } public List GetPageList(List conditionalList, PageModel page) { int count = 0; var result = Context.Queryable().Where(conditionalList).ToPageList(page.PageIndex, page.PageSize, ref count); page.PageCount = count; return result; } public List GetPageList(List conditionalList, PageModel page, Expression> orderByExpression = null, OrderByType orderByType = OrderByType.Asc) { int count = 0; var result = Context.Queryable().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(conditionalList).ToPageList(page.PageIndex, page.PageSize, ref count); page.PageCount = count; return result; } public bool IsAny(Expression> whereExpression) { return Context.Queryable().Where(whereExpression).Any(); } public int Count(Expression> whereExpression) { return Context.Queryable().Where(whereExpression).Count(); } public bool Insert(T insertObj) { return this.Context.Insertable(insertObj).ExecuteCommand() > 0; } public int InsertReturnIdentity(T insertObj) { return this.Context.Insertable(insertObj).ExecuteReturnIdentity(); } public bool InsertRange(T[] insertObjs) { return this.Context.Insertable(insertObjs).ExecuteCommand() > 0; } public bool InsertRange(List insertObjs) { return this.Context.Insertable(insertObjs).ExecuteCommand() > 0; } public bool Update(T updateObj) { return this.Context.Updateable(updateObj).ExecuteCommand() > 0; } public bool UpdateRange(T[] updateObjs) { return this.Context.Updateable(updateObjs).ExecuteCommand() > 0; } public bool UpdateRange(List updateObjs) { return this.Context.Updateable(updateObjs).ExecuteCommand() > 0; } public bool Update(Expression> columns, Expression> whereExpression) { return this.Context.Updateable().UpdateColumns(columns).Where(whereExpression).ExecuteCommand() > 0; } public bool Delete(T deleteObj) { return this.Context.Deleteable().Where(deleteObj).ExecuteCommand() > 0; } public bool Delete(Expression> whereExpression) { return this.Context.Deleteable().Where(whereExpression).ExecuteCommand() > 0; } public bool DeleteById(dynamic id) { return this.Context.Deleteable().In(id).ExecuteCommand() > 0; } public bool DeleteByIds(dynamic[] ids) { return this.Context.Deleteable().In(ids).ExecuteCommand() > 0; } } }