Add SimpleClient

This commit is contained in:
sunkaixuan 2017-06-23 19:47:58 +08:00
parent cb6606bf42
commit 321cc01198
3 changed files with 92 additions and 2 deletions

View 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;
}
}
}

View File

@ -27,6 +27,7 @@ namespace SqlSugar
protected IRewritableMethods _RewritableMethods;
protected IDbMaintenance _DbMaintenance;
protected QueryFilterProvider _QueryFilterProvider;
protected SimpleClient _SimpleClient;
#endregion
#region Init mppingInfo

View File

@ -206,7 +206,7 @@ namespace SqlSugar
queryable.Where(joinExpression);
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>();
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()
{