This commit is contained in:
sunkaixuan
2024-08-24 18:41:46 +08:00
2 changed files with 126 additions and 48 deletions

View File

@@ -26,7 +26,9 @@ namespace SqlSugar
IUpdateable<T> AsUpdateable();
IUpdateable<T> AsUpdateable(T[] updateObjs);
int Count(Expression<Func<T, bool>> whereExpression);
int Count(List<IConditionalModel> conditionalModels);
bool Delete(Expression<Func<T, bool>> whereExpression);
bool Delete(List<IConditionalModel> conditionalModels);
bool Delete(T deleteObj);
bool Delete(List<T> deleteObjs);
bool DeleteById(dynamic id);
@@ -34,12 +36,20 @@ namespace SqlSugar
T GetById(dynamic id);
List<T> GetList();
List<T> GetList(Expression<Func<T, bool>> whereExpression);
List<T> GetList(List<IConditionalModel> conditionalList);
List<T> GetList(Expression<Func<T, bool>> whereExpression, List<OrderByModel> orderByModels);
List<T> GetList(List<IConditionalModel> conditionalList, List<OrderByModel> orderByModels);
List<T> GetPageList(Expression<Func<T, bool>> whereExpression, PageModel page);
List<T> GetPageList(Expression<Func<T, bool>> whereExpression, PageModel page, List<OrderByModel> orderByModels);
List<T> GetPageList(Expression<Func<T, bool>> whereExpression, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc);
List<T> GetPageList(List<IConditionalModel> conditionalList, PageModel page);
List<T> GetPageList(List<IConditionalModel> conditionalList, PageModel page, List<OrderByModel> orderByModels);
List<T> GetPageList(List<IConditionalModel> conditionalList, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc);
T GetSingle(Expression<Func<T, bool>> whereExpression);
T GetSingle(List<IConditionalModel> conditionalModels);
T GetFirst(Expression<Func<T, bool>> whereExpression);
T GetFirst(List<IConditionalModel> conditionalModels);
T GetFirst(List<IConditionalModel> conditionalModels, List<OrderByModel> orderByModels);
bool Insert(T insertObj);
bool InsertOrUpdate(T data);
bool InsertOrUpdate(List<T> datas);
@@ -53,6 +63,7 @@ namespace SqlSugar
bool IsAny(Expression<Func<T, bool>> whereExpression);
bool IsAny(List<IConditionalModel> conditionalModels);
bool Update(Expression<Func<T, T>> columns, Expression<Func<T, bool>> whereExpression);
bool UpdateSetColumnsTrue(Expression<Func<T, T>> columns, Expression<Func<T, bool>> whereExpression);
bool Update(T updateObj);

View File

@@ -13,9 +13,9 @@ namespace SqlSugar
public partial class SimpleClient<T> : ISugarRepository, ISimpleClient<T> where T : class, new()
{
#region Interface
public ISqlSugarClient Context { get; set; }
public virtual ISqlSugarClient Context { get; set; }
public ITenant AsTenant()
public virtual ITenant AsTenant()
{
var result = this.Context as ITenant;
if (result == null && this.Context is SqlSugarProvider)
@@ -28,7 +28,7 @@ namespace SqlSugar
}
return result;
}
public ISqlSugarClient AsSugarClient()
public virtual ISqlSugarClient AsSugarClient()
{
return this.Context;
}
@@ -51,7 +51,7 @@ namespace SqlSugar
sm.Context = this.Context.CopyNew();
return sm;
}
public RepositoryType CopyNew<RepositoryType>() where RepositoryType : ISugarRepository
public virtual RepositoryType CopyNew<RepositoryType>() where RepositoryType : ISugarRepository
{
Type type = typeof(RepositoryType);
var isAnyParamter = type.GetConstructors().Any(z => z.GetParameters().Any());
@@ -77,7 +77,7 @@ namespace SqlSugar
}
return result;
}
public RepositoryType CopyNew<RepositoryType>(IServiceProvider serviceProvider) where RepositoryType : ISugarRepository
public virtual RepositoryType CopyNew<RepositoryType>(IServiceProvider serviceProvider) where RepositoryType : ISugarRepository
{
var instance = handleDependencies(typeof(RepositoryType), serviceProvider, true);
return (RepositoryType)instance;
@@ -169,7 +169,7 @@ namespace SqlSugar
}
return false;
}
public RepositoryType ChangeRepository<RepositoryType>() where RepositoryType : ISugarRepository
public virtual RepositoryType ChangeRepository<RepositoryType>() where RepositoryType : ISugarRepository
{
Type type = typeof(RepositoryType);
var isAnyParamter = type.GetConstructors().Any(z => z.GetParameters().Any());
@@ -189,44 +189,44 @@ namespace SqlSugar
}
return result;
}
public RepositoryType ChangeRepository<RepositoryType>(IServiceProvider serviceProvider) where RepositoryType : ISugarRepository
public virtual RepositoryType ChangeRepository<RepositoryType>(IServiceProvider serviceProvider) where RepositoryType : ISugarRepository
{
var instance = handleDependencies(typeof(RepositoryType), serviceProvider, false);
return (RepositoryType)instance;
}
public ISugarQueryable<T> AsQueryable()
public virtual ISugarQueryable<T> AsQueryable()
{
return Context.Queryable<T>();
}
public IInsertable<T> AsInsertable(T insertObj)
public virtual IInsertable<T> AsInsertable(T insertObj)
{
return Context.Insertable<T>(insertObj);
}
public IInsertable<T> AsInsertable(T[] insertObjs)
public virtual IInsertable<T> AsInsertable(T[] insertObjs)
{
return Context.Insertable<T>(insertObjs);
}
public IInsertable<T> AsInsertable(List<T> insertObjs)
public virtual IInsertable<T> AsInsertable(List<T> insertObjs)
{
return Context.Insertable<T>(insertObjs);
}
public IUpdateable<T> AsUpdateable(T updateObj)
public virtual IUpdateable<T> AsUpdateable(T updateObj)
{
return Context.Updateable<T>(updateObj);
}
public IUpdateable<T> AsUpdateable(T[] updateObjs)
public virtual IUpdateable<T> AsUpdateable(T[] updateObjs)
{
return Context.Updateable<T>(updateObjs);
}
public IUpdateable<T> AsUpdateable(List<T> updateObjs)
public virtual IUpdateable<T> AsUpdateable(List<T> updateObjs)
{
return Context.Updateable<T>(updateObjs);
}
public IUpdateable<T> AsUpdateable()
public virtual IUpdateable<T> AsUpdateable()
{
return Context.Updateable<T>();
}
public IDeleteable<T> AsDeleteable()
public virtual IDeleteable<T> AsDeleteable()
{
return Context.Deleteable<T>();
}
@@ -691,6 +691,73 @@ namespace SqlSugar
this.Context.Ado.CancellationToken = cancellationToken;
return await this.Context.Deleteable<T>().In(ids).ExecuteCommandAsync() > 0;
}
public int Count(List<IConditionalModel> conditionalModels)
{
return Context.Queryable<T>().Where(conditionalModels).Count();
}
public bool Delete(List<IConditionalModel> conditionalModels)
{
return Context.Deleteable<T>().Where(conditionalModels).ExecuteCommandHasChange();
}
public List<T> GetList(Expression<Func<T, bool>> whereExpression, List<OrderByModel> orderByModels)
{
return Context.Queryable<T>().Where(whereExpression).OrderBy(orderByModels).ToList();
}
public List<T> GetList(List<IConditionalModel> conditionalList)
{
return Context.Queryable<T>().Where(conditionalList).ToList();
}
public List<T> GetList(List<IConditionalModel> conditionalList, List<OrderByModel> orderByModels)
{
return Context.Queryable<T>().Where(conditionalList).OrderBy(orderByModels).ToList();
}
public List<T> GetPageList(Expression<Func<T, bool>> whereExpression, PageModel page, List<OrderByModel> orderByModels)
{
var total = 0;
var list = Context.Queryable<T>().Where(whereExpression).OrderBy(orderByModels).ToPageList(page.PageIndex, page.PageSize, ref total);
page.TotalCount = total;
return list;
}
public List<T> GetPageList(List<IConditionalModel> conditionalList, PageModel page, List<OrderByModel> orderByModels)
{
var total = 0;
var list = Context.Queryable<T>().Where(conditionalList).OrderBy(orderByModels).ToPageList(page.PageIndex, page.PageSize, ref total);
page.TotalCount = total;
return list;
}
public T GetSingle(List<IConditionalModel> conditionalModels)
{
return Context.Queryable<T>().Where(conditionalModels).Single();
}
public T GetFirst(List<IConditionalModel> conditionalModels)
{
return Context.Queryable<T>().Where(conditionalModels).First();
}
public bool IsAny(List<IConditionalModel> conditionalModels)
{
return Context.Queryable<T>().Where(conditionalModels).Any();
}
public T GetFirst(Expression<Func<T, bool>> whereExpression, List<OrderByModel> orderByModels)
{
return Context.Queryable<T>().Where(whereExpression).OrderBy(orderByModels).First();
}
public T GetFirst(List<IConditionalModel> conditionalModels, List<OrderByModel> orderByModels)
{
return Context.Queryable<T>().Where(conditionalModels).OrderBy(orderByModels).First();
}
#endregion
}