- 解决 vb.net 表达式无法解析字符串比较;#140

This commit is contained in:
28810 2019-12-15 13:04:08 +08:00
parent f162520202
commit c7b63ef474
5 changed files with 70 additions and 0 deletions

View File

@ -0,0 +1,26 @@
Imports System
Module Program
Sub Main(args As String())
Console.WriteLine("Hello World!")
Dim fsql = New FreeSql.FreeSqlBuilder() _
.UseConnectionString(FreeSql.DataType.Sqlite, "data source=testvb.db") _
.UseAutoSyncStructure(True) _
.UseMonitorCommand(Sub(cmd) Trace.WriteLine(cmd.CommandText)) _
.Build()
REM Microsoft.VisualBasic.CompilerServices.Operators.CompareString()
Dim List1 = fsql.Select(Of Testvb).Where(Function(a) a.Id = 100).ToList()
Dim List2 = fsql.Select(Of Testvb).Where(Function(a) a.Title = "xxx").ToList()
Dim List3 = fsql.Select(Of Testvb).Where(Function(a) a.Title <> "xxx").ToList()
fsql.Dispose()
End Sub
End Module
Class Testvb
Property Id As Integer
Property Title As String
End Class

View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<RootNamespace>test_vb</RootNamespace>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Providers\FreeSql.Provider.Sqlite\FreeSql.Provider.Sqlite.csproj" />
</ItemGroup>
</Project>

View File

@ -68,6 +68,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "orm_vs_net40", "Examples\or
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Generator", "Extensions\FreeSql.Generator\FreeSql.Generator.csproj", "{6A3A4470-7DF7-411B-AAD7-755D7A9DB5A4}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Generator", "Extensions\FreeSql.Generator\FreeSql.Generator.csproj", "{6A3A4470-7DF7-411B-AAD7-755D7A9DB5A4}"
EndProject EndProject
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "test_vb", "Examples\test_vb\test_vb.vbproj", "{0A2206B1-1D34-45F4-B028-E3C5D6F02295}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -402,6 +404,18 @@ Global
{6A3A4470-7DF7-411B-AAD7-755D7A9DB5A4}.Release|x64.Build.0 = Release|Any CPU {6A3A4470-7DF7-411B-AAD7-755D7A9DB5A4}.Release|x64.Build.0 = Release|Any CPU
{6A3A4470-7DF7-411B-AAD7-755D7A9DB5A4}.Release|x86.ActiveCfg = Release|Any CPU {6A3A4470-7DF7-411B-AAD7-755D7A9DB5A4}.Release|x86.ActiveCfg = Release|Any CPU
{6A3A4470-7DF7-411B-AAD7-755D7A9DB5A4}.Release|x86.Build.0 = Release|Any CPU {6A3A4470-7DF7-411B-AAD7-755D7A9DB5A4}.Release|x86.Build.0 = Release|Any CPU
{0A2206B1-1D34-45F4-B028-E3C5D6F02295}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0A2206B1-1D34-45F4-B028-E3C5D6F02295}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0A2206B1-1D34-45F4-B028-E3C5D6F02295}.Debug|x64.ActiveCfg = Debug|Any CPU
{0A2206B1-1D34-45F4-B028-E3C5D6F02295}.Debug|x64.Build.0 = Debug|Any CPU
{0A2206B1-1D34-45F4-B028-E3C5D6F02295}.Debug|x86.ActiveCfg = Debug|Any CPU
{0A2206B1-1D34-45F4-B028-E3C5D6F02295}.Debug|x86.Build.0 = Debug|Any CPU
{0A2206B1-1D34-45F4-B028-E3C5D6F02295}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0A2206B1-1D34-45F4-B028-E3C5D6F02295}.Release|Any CPU.Build.0 = Release|Any CPU
{0A2206B1-1D34-45F4-B028-E3C5D6F02295}.Release|x64.ActiveCfg = Release|Any CPU
{0A2206B1-1D34-45F4-B028-E3C5D6F02295}.Release|x64.Build.0 = Release|Any CPU
{0A2206B1-1D34-45F4-B028-E3C5D6F02295}.Release|x86.ActiveCfg = Release|Any CPU
{0A2206B1-1D34-45F4-B028-E3C5D6F02295}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -426,6 +440,7 @@ Global
{C57444BA-8BF7-4790-A864-7F237123219B} = {2A381C57-2697-427B-9F10-55DA11FD02E4} {C57444BA-8BF7-4790-A864-7F237123219B} = {2A381C57-2697-427B-9F10-55DA11FD02E4}
{1674BCE3-EEB4-4003-A2A7-06F51EFAEA23} = {94C8A78D-AA15-47B2-A348-530CD86BFC1B} {1674BCE3-EEB4-4003-A2A7-06F51EFAEA23} = {94C8A78D-AA15-47B2-A348-530CD86BFC1B}
{6A3A4470-7DF7-411B-AAD7-755D7A9DB5A4} = {4A92E8A6-9A6D-41A1-9CDA-DE10899648AA} {6A3A4470-7DF7-411B-AAD7-755D7A9DB5A4} = {4A92E8A6-9A6D-41A1-9CDA-DE10899648AA}
{0A2206B1-1D34-45F4-B028-E3C5D6F02295} = {94C8A78D-AA15-47B2-A348-530CD86BFC1B}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {089687FD-5D25-40AB-BA8A-A10D1E137F98} SolutionGuid = {089687FD-5D25-40AB-BA8A-A10D1E137F98}

View File

@ -417,6 +417,20 @@ namespace FreeSql.Internal
} }
public string ExpressionBinary(string oper, Expression leftExp, Expression rightExp, ExpTSC tsc) public string ExpressionBinary(string oper, Expression leftExp, Expression rightExp, ExpTSC tsc)
{ {
if (leftExp.NodeType == ExpressionType.Call &&
rightExp.NodeType == ExpressionType.Constant &&
new[] { "=", "<>" }.Contains(oper))
{
var leftExpCall = leftExp as MethodCallExpression;
//vb 语法,将字符串比较转换为了 CompareString
if (leftExpCall.Method.Name == "CompareString" &&
leftExpCall.Method.DeclaringType?.FullName == "Microsoft.VisualBasic.CompilerServices.Operators" &&
leftExpCall.Arguments.Count == 3 &&
leftExpCall.Arguments[2].Type == typeof(bool) &&
rightExp.Type == typeof(int) &&
(int)(rightExp as ConstantExpression).Value == 0)
return ExpressionBinary(oper, leftExpCall.Arguments[0], leftExpCall.Arguments[1], tsc);
}
switch (oper) switch (oper)
{ {
case "OR": case "OR":

View File

@ -9,6 +9,8 @@ using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
//jdbc:gbasedbt-sqli://192.168.164.10:9088/gbasedb:GBASEDBTSERVER=gbaseserver;DB_LOCALE=zh_CN.GB18030-2000;CLIENT_LOCALE=zh_CN.GB18030-2000;NEWCODESET=GB18030,GB18030-2000,5488;
namespace FreeSql.Odbc.GBase namespace FreeSql.Odbc.GBase
{ {