FreeSql icon indicating copy to clipboard operation
FreeSql copied to clipboard

数组的Contains查询错误bug

Open lable opened this issue 1 month ago • 5 comments

问题描述及重现代码:

// c# code
// ImportLogIds的类型为 long[]
            try
            {
                freeSql.Select<Core.Domain.CorePayOrder.CorePayOrderEntity>()
                .Where(a => a.ImportLogIds.Contains(0))
                .DisableGlobalFilter(FreeSql.FreeSqlExtensions.BranchFilters)
                .Where(a => !a.BranchId.HasValue)
                .Any();
            }
            catch (System.Exception ex)
            {
                logger?.LogError(ex, "FreeSql Array解析错误");
            }

报以下异常: System.Exception: FreeSql: Function expression op_Implicit(a.ImportLogIds) parsing not implemented at FreeSql.Internal.CommonExpression.ExpressionLambdaToSql(Expression exp, ExpTSC tsc) at FreeSql.PostgreSQL.PostgreSQLExpression.<>c__DisplayClass1_0.<ExpressionLambdaToSqlOther>b__0(Expression exparg) at FreeSql.PostgreSQL.PostgreSQLExpression.ExpressionLambdaToSqlOther(Expression exp, ExpTSC tsc) at FreeSql.Internal.CommonExpression.ExpressionLambdaToSql(Expression exp, ExpTSC tsc) at FreeSql.Internal.CommonExpression.ExpressionWhereLambda(List1 _tables, Func3 _tableRule, Expression exp, BaseDiyMemberExpression diymemexp, List1 whereGlobalFilter, List1 dbParams) at FreeSql.Internal.CommonProvider.Select0Provider2.InternalWhere(Expression exp) at FreeSql.Internal.CommonProvider.Select1Provider1.WhereIf(Boolean condition, Expression1 exp) at FreeSql.Internal.CommonProvider.Select1Provider1.Where(Expression`1 exp)

数据库版本

postgresql 15

安装的Nuget包

.net framework/. net core? 及具体版本

.net 8.0

lable avatar Nov 20 '25 08:11 lable

强制引用 <PackageReference Include="FreeSql" Version="3.5.303" /> 后解析正确了,但是类型转换不正确:

[16:46:25 DBG] curd sql: SELECT 1 as1 FROM "core_payorder" a WHERE ((a."import_log_ids" @> array[0])) AND (a."branch_id" IS NULL) AND (a."deleted_on" IS NULL) limit 1 <s:FreeSqlContextExtensions> [16:46:25 ERR] Message:42883: operator does not exist: bigint[] @> integer[]

POSITION: 68 StackTrace: at Npgsql.Internal.NpgsqlConnector.ReadMessageLong(Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage) at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder1.StateMachineBox1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token) at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken) at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken) at Npgsql.NpgsqlDataReader.NextResult() at Npgsql.NpgsqlCommand.ExecuteReader(Boolean async, CommandBehavior behavior, CancellationToken cancellationToken) at Npgsql.NpgsqlCommand.ExecuteReader(Boolean async, CommandBehavior behavior, CancellationToken cancellationToken) at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior) at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior) at FreeSql.Internal.CommonProvider.AdoProvider.ExecuteReaderMultiple(Int32 multipleResult, DbConnection connection, DbTransaction transaction, Action2 fetchHandler, Action2 schemaHandler, CommandType cmdType, String cmdText, Int32 cmdTimeout, DbParameter[] cmdParms) CommandText:SELECT 1 as1 FROM "core_payorder" a WHERE ((a."import_log_ids" @> array[0])) AND (a."branch_id" IS NULL) AND (a."deleted_on" IS NULL) limit 1

正确的SQL应为: SELECT 1 as1 FROM "core_payorder" a WHERE ((a."import_log_ids" @> array[0]::bigint)) AND (a."branch_id" IS NULL) AND (a."deleted_on" IS NULL) limit 1

lable avatar Nov 20 '25 08:11 lable

https://github.com/dotnetcore/FreeSql/blob/e7961d006ce47298edd7f4ef7d6d2b0ff49279eb/Providers/FreeSql.Provider.PostgreSQL/PostgreSQLExpression.cs#L245

麻烦在这里 debug 一下,看下 objExp, dbinfo 拿到的内容是什么

2881099 avatar Nov 20 '25 15:11 2881099

FreeSql/Providers/FreeSql.Provider.PostgreSQL/PostgreSQLExpression.cs

Line 245 in e7961d0

if (objExp != null) 麻烦在这里 debug 一下,看下 objExp, dbinfo 拿到的内容是什么

dbinfo 是 null

Image

lable avatar Nov 21 '25 02:11 lable

这玩意很坑,编译成 ReadOnlySpan 了

2881099 avatar Nov 21 '25 12:11 2881099

这个有结果了吗? 升级net10全部降回来了 有没有其他方案?

yuefengkai avatar Dec 09 '25 06:12 yuefengkai