mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-19 01:58:13 +08:00
Add SimpleClient
This commit is contained in:
76
Src/Asp.NetCore/SqlServerTest/src/SqlSugar/SimpleClient.cs
Normal file
76
Src/Asp.NetCore/SqlServerTest/src/SqlSugar/SimpleClient.cs
Normal file
@@ -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<T>(dynamic id) where T : class, new()
|
||||||
|
{
|
||||||
|
return Context.Queryable<T>().InSingle(id);
|
||||||
|
}
|
||||||
|
public List<T> GetList<T>() where T : class, new()
|
||||||
|
{
|
||||||
|
return Context.Queryable<T>().ToList();
|
||||||
|
}
|
||||||
|
public List<T> GetList<T>(Expression<Func<T, bool>> whereExpression) where T : class, new()
|
||||||
|
{
|
||||||
|
return Context.Queryable<T>().Where(whereExpression).ToList();
|
||||||
|
}
|
||||||
|
public bool Insert<T>(T insertObj) where T : class, new()
|
||||||
|
{
|
||||||
|
return this.Context.Insertable(insertObj).ExecuteCommand() > 0;
|
||||||
|
}
|
||||||
|
public int InsertReturnIdentity<T>(T insertObj) where T : class, new()
|
||||||
|
{
|
||||||
|
return this.Context.Insertable(insertObj).ExecuteReutrnIdentity();
|
||||||
|
}
|
||||||
|
public bool InsertRange<T>(T[] insertObjs) where T : class, new()
|
||||||
|
{
|
||||||
|
return this.Context.Insertable(insertObjs).ExecuteCommand() > 0;
|
||||||
|
}
|
||||||
|
public bool InsertRange<T>(List<T>[] insertObjs) where T : class, new()
|
||||||
|
{
|
||||||
|
return this.Context.Insertable(insertObjs).ExecuteCommand() > 0;
|
||||||
|
}
|
||||||
|
public bool Update<T>(T updateObj) where T : class, new()
|
||||||
|
{
|
||||||
|
return this.Context.Updateable(updateObj).ExecuteCommand() > 0;
|
||||||
|
}
|
||||||
|
public bool Update<T>(Expression<Func<T, T>> columns, Expression<Func<T, bool>> whereExpression) where T : class, new()
|
||||||
|
{
|
||||||
|
return this.Context.Updateable<T>().UpdateColumns(columns).Where(whereExpression).ExecuteCommand() > 0;
|
||||||
|
}
|
||||||
|
public bool Delete<T>(T deleteObj) where T : class, new()
|
||||||
|
{
|
||||||
|
return this.Context.Deleteable<T>().Where(deleteObj).ExecuteCommand() > 0;
|
||||||
|
}
|
||||||
|
public bool Delete<T>(Expression<Func<T, bool>> whereExpression) where T : class, new()
|
||||||
|
{
|
||||||
|
return this.Context.Deleteable<T>().Where(whereExpression).ExecuteCommand() > 0;
|
||||||
|
}
|
||||||
|
public bool DeleteById<T>(dynamic id) where T : class, new()
|
||||||
|
{
|
||||||
|
return this.Context.Deleteable<T>().In(id).ExecuteCommand() > 0;
|
||||||
|
}
|
||||||
|
public bool DeleteByIds<T>(dynamic[] ids) where T : class, new()
|
||||||
|
{
|
||||||
|
return this.Context.Deleteable<T>().In(ids).ExecuteCommand() > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -27,6 +27,7 @@ namespace SqlSugar
|
|||||||
protected IRewritableMethods _RewritableMethods;
|
protected IRewritableMethods _RewritableMethods;
|
||||||
protected IDbMaintenance _DbMaintenance;
|
protected IDbMaintenance _DbMaintenance;
|
||||||
protected QueryFilterProvider _QueryFilterProvider;
|
protected QueryFilterProvider _QueryFilterProvider;
|
||||||
|
protected SimpleClient _SimpleClient;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Init mppingInfo
|
#region Init mppingInfo
|
||||||
|
@@ -206,7 +206,7 @@ namespace SqlSugar
|
|||||||
queryable.Where(joinExpression);
|
queryable.Where(joinExpression);
|
||||||
return queryable;
|
return queryable;
|
||||||
}
|
}
|
||||||
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7> Queryable<T, T2, T3, T4, T5, T6, T7>(Expression<Func<T, T2, T3, T4, T5, T6, T7,bool>> joinExpression) where T : class, new()
|
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7> Queryable<T, T2, T3, T4, T5, T6, T7>(Expression<Func<T, T2, T3, T4, T5, T6, T7, bool>> joinExpression) where T : class, new()
|
||||||
{
|
{
|
||||||
InitMppingInfo<T, T2, T3, T4, T5, T6>();
|
InitMppingInfo<T, T2, T3, T4, T5, T6>();
|
||||||
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7) };
|
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7) };
|
||||||
@@ -331,7 +331,7 @@ namespace SqlSugar
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Gobal Filter
|
#region Gobal Filter
|
||||||
public QueryFilterProvider QueryFilter
|
public virtual QueryFilterProvider QueryFilter
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
@@ -349,6 +349,19 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region SimpleClient
|
||||||
|
public virtual SimpleClient SimpleClient
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_SimpleClient == null) {
|
||||||
|
_SimpleClient = new SimpleClient(this);
|
||||||
|
}
|
||||||
|
return _SimpleClient;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Dispose OR Close
|
#region Dispose OR Close
|
||||||
public virtual void Close()
|
public virtual void Close()
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user