diff --git a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/ConditionalExpressionResolve.cs b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/ConditionalExpressionResolve.cs index 784a909bf..7a335c71f 100644 --- a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/ConditionalExpressionResolve.cs +++ b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/ConditionalExpressionResolve.cs @@ -17,6 +17,11 @@ namespace SqlSugar express.IfTrue, express.IfFalse }; + if (IsBoolMember(express)) + { + Expression trueValue = Expression.Constant(true); + args[0]= ExpressionBuilderHelper.CreateExpression(express.Test, trueValue, ExpressionType.And); + } var isLeft = parameter.IsLeft; MethodCallExpressionModel model = new MethodCallExpressionModel(); model.Args = new List(); @@ -40,5 +45,10 @@ namespace SqlSugar break; } } + + private static bool IsBoolMember(ConditionalExpression express) + { + return express.Test is MemberExpression && (express.Test as MemberExpression).Expression is ParameterExpression; + } } } diff --git a/Src/Asp.NetCore2/SqlSugar/Interface/ITenant.cs b/Src/Asp.NetCore2/SqlSugar/Interface/ITenant.cs index 84ed87555..3c0d09780 100644 --- a/Src/Asp.NetCore2/SqlSugar/Interface/ITenant.cs +++ b/Src/Asp.NetCore2/SqlSugar/Interface/ITenant.cs @@ -24,6 +24,13 @@ namespace SqlSugar SqlSugarScopeProvider GetConnectionScope(dynamic configId); SqlSugarProvider GetConnectionWithAttr(); SqlSugarScopeProvider GetConnectionScopeWithAttr(); + ISugarQueryable QueryableWithAttr(); + IInsertable InsertableWithAttr(T insertObj) where T : class, new(); + IInsertable InsertableWithAttr(List insertObjs) where T : class, new(); + IUpdateable UpdateableWithAttr(T updateObj) where T : class, new(); + IUpdateable UpdateableWithAttr(List updateObjs) where T : class, new(); + IDeleteable DeleteableWithAttr(T deleteObjs) where T : class, new(); + IDeleteable DeleteableWithAttr(List deleteObjs) where T : class, new(); bool IsAnyConnection(dynamic configId); void Close(); diff --git a/Src/Asp.NetCore2/SqlSugar/SqlSugarClient.cs b/Src/Asp.NetCore2/SqlSugar/SqlSugarClient.cs index 488b71181..705928688 100644 --- a/Src/Asp.NetCore2/SqlSugar/SqlSugarClient.cs +++ b/Src/Asp.NetCore2/SqlSugar/SqlSugarClient.cs @@ -1243,5 +1243,36 @@ namespace SqlSugar this.CurrentConnectionConfig = Tenant.ConnectionConfig; } #endregion + + #region Tenant Crud + public ISugarQueryable QueryableWithAttr() + { + return this.GetConnectionWithAttr().Queryable(); + } + public IInsertable InsertableWithAttr(T insertObj) where T : class, new() + { + return this.GetConnectionWithAttr().Insertable(insertObj); + } + public IInsertable InsertableWithAttr(List insertObjs) where T : class, new() + { + return this.GetConnectionWithAttr().Insertable(insertObjs); + } + public IUpdateable UpdateableWithAttr(T updateObj) where T : class, new() + { + return this.GetConnectionWithAttr().Updateable(updateObj); + } + public IUpdateable UpdateableWithAttr(List updateObjs) where T : class, new() + { + return this.GetConnectionWithAttr().Updateable(updateObjs); + } + public IDeleteable DeleteableWithAttr(T deleteObject) where T : class, new() + { + return this.GetConnectionWithAttr().Deleteable(deleteObject); + } + public IDeleteable DeleteableWithAttr(List deleteObjects) where T : class, new() + { + return this.GetConnectionWithAttr().Deleteable(deleteObjects); + } + #endregion } } diff --git a/Src/Asp.NetCore2/SqlSugar/SqlSugarScope.cs b/Src/Asp.NetCore2/SqlSugar/SqlSugarScope.cs index aad57c4a4..1a660cf34 100644 --- a/Src/Asp.NetCore2/SqlSugar/SqlSugarScope.cs +++ b/Src/Asp.NetCore2/SqlSugar/SqlSugarScope.cs @@ -695,5 +695,33 @@ namespace SqlSugar { return ScopedContext.ThenMapperAsync(list, action); } + public ISugarQueryable QueryableWithAttr() + { + return ScopedContext.QueryableWithAttr(); + } + public IInsertable InsertableWithAttr(T insertObj) where T : class, new() + { + return ScopedContext.InsertableWithAttr(insertObj); + } + public IInsertable InsertableWithAttr(List insertObjs) where T : class, new() + { + return ScopedContext.InsertableWithAttr(insertObjs); + } + public IUpdateable UpdateableWithAttr(T updateObj) where T : class, new() + { + return ScopedContext.UpdateableWithAttr(updateObj); + } + public IUpdateable UpdateableWithAttr(List updateObjs) where T : class, new() + { + return ScopedContext.UpdateableWithAttr(updateObjs); + } + public IDeleteable DeleteableWithAttr(T deleteObj) where T : class, new() + { + return ScopedContext.DeleteableWithAttr(deleteObj); + } + public IDeleteable DeleteableWithAttr(List deleteObjs) where T : class, new() + { + return ScopedContext.DeleteableWithAttr(deleteObjs); + } } } diff --git a/Src/Asp.NetCore2/SqlSugar/Utilities/ExpressionBuilderHelper.cs b/Src/Asp.NetCore2/SqlSugar/Utilities/ExpressionBuilderHelper.cs index a096bf10b..d454c0685 100644 --- a/Src/Asp.NetCore2/SqlSugar/Utilities/ExpressionBuilderHelper.cs +++ b/Src/Asp.NetCore2/SqlSugar/Utilities/ExpressionBuilderHelper.cs @@ -12,6 +12,22 @@ namespace SqlSugar { public class ExpressionBuilderHelper { + /// + /// Create Expression + /// + public static Expression CreateExpression(Expression left, Expression value, ExpressionType type) + { + + if (type == ExpressionType.Equal) + { + return Expression.Equal(left, Expression.Convert(value, left.Type)); + } + else + { + //Not implemented, later used in writing + return Expression.Equal(left, Expression.Convert(value, left.Type)); + } + } public static Expression> CreateNewFields(EntityInfo entity,List propertyNames) { Type sourceType = typeof(T);