diff --git a/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/SimpleClient.cs b/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/SimpleClient.cs new file mode 100644 index 000000000..9288e979f --- /dev/null +++ b/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/SimpleClient.cs @@ -0,0 +1,76 @@ +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 List GetList(Expression> whereExpression) where T : class, new() + { + return Context.Queryable().Where(whereExpression).ToList(); + } + 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).ExecuteReutrnIdentity(); + } + 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 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; + } + } +} diff --git a/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/SqlSugarAccessory.cs b/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/SqlSugarAccessory.cs index 8d78b2682..cee36d6c7 100644 --- a/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/SqlSugarAccessory.cs +++ b/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/SqlSugarAccessory.cs @@ -27,6 +27,7 @@ namespace SqlSugar protected IRewritableMethods _RewritableMethods; protected IDbMaintenance _DbMaintenance; protected QueryFilterProvider _QueryFilterProvider; + protected SimpleClient _SimpleClient; #endregion #region Init mppingInfo diff --git a/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/SqlSugarClient.cs b/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/SqlSugarClient.cs index cbbcecdff..7aff8a584 100644 --- a/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/SqlSugarClient.cs +++ b/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/SqlSugarClient.cs @@ -206,7 +206,7 @@ namespace SqlSugar queryable.Where(joinExpression); return queryable; } - public virtual ISugarQueryable Queryable(Expression> joinExpression) where T : class, new() + public virtual ISugarQueryable Queryable(Expression> joinExpression) where T : class, new() { InitMppingInfo(); var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7) }; @@ -331,7 +331,7 @@ namespace SqlSugar #endregion #region Gobal Filter - public QueryFilterProvider QueryFilter + public virtual QueryFilterProvider QueryFilter { get { @@ -349,6 +349,19 @@ namespace SqlSugar } #endregion + #region SimpleClient + public virtual SimpleClient SimpleClient + { + get + { + if (_SimpleClient == null) { + _SimpleClient = new SimpleClient(this); + } + return _SimpleClient; + } + } + #endregion + #region Dispose OR Close public virtual void Close() {