From b14d9d5752f65e47ab1bc90d65a2e28a7348d6ce Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Mon, 13 Dec 2021 15:17:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20PetaPoco=20=E5=A2=9E=E5=8A=A0=E5=AF=B9?= =?UTF-8?q?=E6=9E=9A=E4=B8=BE=E7=B1=BB=E5=9E=8B=E6=90=9C=E7=B4=A2=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extensions/DatabaseExtensions.cs | 42 +++++++++++++------ 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Extensions/DatabaseExtensions.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Extensions/DatabaseExtensions.cs index 041965f7..a4c00840 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Extensions/DatabaseExtensions.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Extensions/DatabaseExtensions.cs @@ -90,20 +90,36 @@ namespace BootstrapAdmin.Web.Extensions case ExpressionType.GreaterThanOrEqual: case ExpressionType.LessThan: case ExpressionType.LessThanOrEqual: - var binaryExp = (expression as BinaryExpression)!; - var left = (binaryExp.Left as MemberExpression)!; - - // 查找 PetaPoco.Column 标签 - var columnName = GetColumnName(left.Member) ?? left.Member.Name; - - // 查找操作符右侧 - var right = (binaryExp.Right as ConstantExpression)!; - var v = right.Value; - - if (v != null) + if (expression is BinaryExpression binaryExp) { - var operatorExp = GetOperatorExpression(expression); - sql.Where($"{db.Provider.EscapeSqlIdentifier(columnName)} {operatorExp} @0", v); + MemberExpression? left = null; + if (binaryExp.Left is MethodCallExpression methodLeft && methodLeft.Method.Name == "ToString" && methodLeft.Object is MemberExpression p && p.Type.IsEnum) + { + // 枚举转字符串 + left = p; + } + else if (binaryExp.Left is MemberExpression m) + { + left = m; + } + + if (left != null) + { + // 查找 PetaPoco.Column 标签 + var columnName = GetColumnName(left.Member) ?? left.Member.Name; + + // 查找操作符右侧 + if (binaryExp.Right is ConstantExpression right) + { + var v = right.Value; + + if (v != null) + { + var operatorExp = GetOperatorExpression(expression); + sql.Where($"{db.Provider.EscapeSqlIdentifier(columnName)} {operatorExp} @0", v); + } + } + } } break;