Beim Versuch, den LINQ-Abfrageparameterausdruck auszuwerten, wurde eine Ausnahme ausgelöstC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Beim Versuch, den LINQ-Abfrageparameterausdruck auszuwerten, wurde eine Ausnahme ausgelöst

Post by Anonymous »

Haben Sie eine ziemlich einfache LINQ-Abfrage:

Code: Select all

var objectExternalIds = new string[] { "abc" };
var query = from order in Context.Order
join apointment in Context.Appointment on order.Nr equals apointment.OrderNr
where objectExternalIds.Contains(order.ObjectId)
select apointment.Id;

var result = await query.ToListAsync(cancellationToken);
Dies erzeugt den Fehler:

Code: Select all

An exception was thrown while attempting to evaluate the LINQ query parameter expression 'op_Implicit(Convert(value(Application.Shared.DataWrappers.Order.OrderDataWrapper+c__DisplayClass23_0).objectExternalIds, String[]))'. See the inner exception for more information.
GenericArguments[1], 'System.ReadOnlySpan`1[System.String]', on 'System.Linq.Expressions.Interpreter.FuncCallInstruction`2[T0,TRet]' violates the constraint of type 'TRet'.
GenericArguments[1], 'System.ReadOnlySpan`1[System.String]', on 'System.Linq.Expressions.Interpreter.FuncCallInstruction`2[T0,TRet]' violates the constraint of type parameter 'TRet'.
Ich verwende eine MySql-Datenbank mit Pomelo.EntityFrameworkCore.MySql als Anbieter
Ich bekomme diesen Fehler nicht, sollte ziemlich eng sein
BEARBEITEN:
Kontextklassen:

Code: Select all

public class Order {
public int Id { get; set; }
public string ObjectId { get; set; }
...
}

public class Appointment {
public int Id { get; set; }
public int? OrderNr { get; set; }
...
}
DB-Schema:

Code: Select all

CREATE TABLE `Order` (
`Nr` int(10) NOT NULL DEFAULT '0',
`ObjectId` varchar(50) COLLATE utf8_german2_ci DEFAULT NULL,
PRIMARY KEY (`Nr`),
...
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_german2_ci;

CREATE TABLE `Appointment` (
`ID` int(10) NOT NULL AUTO_INCREMENT,
`OrderNr` int(10) DEFAULT '0',
PRIMARY KEY (`ID`),
...
) ENGINE=InnoDB AUTO_INCREMENT=20848625 DEFAULT CHARSET=utf8 COLLATE=utf8_german2_ci;
Vollständige Ausnahme:

Code: Select all

System.InvalidOperationException
HResult=0x80131509
Message=An exception was thrown while attempting to evaluate the LINQ query parameter expression 'op_Implicit(Convert(value(Application.Shared.DataWrappers.Order.OrderDataWrapper+c__DisplayClass23_0).objectExternalIds, String[]))'.  See the inner exception for more information.
Source=Microsoft.EntityFrameworkCore
StackTrace:
at Microsoft.EntityFrameworkCore.Query.Internal.ParameterExtractingExpressionVisitor.GetValue(Expression expression, String& parameterName)
at Microsoft.EntityFrameworkCore.Query.Internal.ParameterExtractingExpressionVisitor.Evaluate(Expression expression, Boolean generateParameter)
at Microsoft.EntityFrameworkCore.Query.Internal.ParameterExtractingExpressionVisitor.Visit(Expression expression)
at System.Dynamic.Utils.ExpressionVisitorUtils.VisitArguments(ExpressionVisitor visitor, IArgumentProvider nodes)
at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
at Microsoft.EntityFrameworkCore.Query.Internal.ParameterExtractingExpressionVisitor.Visit(Expression expression)
at System.Linq.Expressions.ExpressionVisitor.VisitLambda[T](Expression`1 node)
at Microsoft.EntityFrameworkCore.Query.Internal.ParameterExtractingExpressionVisitor.Visit(Expression expression)
at System.Linq.Expressions.ExpressionVisitor.VisitUnary(UnaryExpression node)
at Microsoft.EntityFrameworkCore.Query.Internal.ParameterExtractingExpressionVisitor.Visit(Expression expression)
at System.Dynamic.Utils.ExpressionVisitorUtils.VisitArguments(ExpressionVisitor visitor, IArgumentProvider nodes)
at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
at Microsoft.EntityFrameworkCore.Query.Internal.ParameterExtractingExpressionVisitor.Visit(Expression expression)
at System.Dynamic.Utils.ExpressionVisitorUtils.VisitArguments(ExpressionVisitor visitor, IArgumentProvider nodes)
at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
at Microsoft.EntityFrameworkCore.Query.Internal.ParameterExtractingExpressionVisitor.Visit(Expression expression)
at Microsoft.EntityFrameworkCore.Query.Internal.ParameterExtractingExpressionVisitor.ExtractParameters(Expression expression, Boolean clearEvaluatedValues)
at Microsoft.EntityFrameworkCore.Query.Internal.ParameterExtractingExpressionVisitor.ExtractParameters(Expression expression)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExtractParameters(Expression query, IParameterValues parameterValues, IDiagnosticsLogger`1 logger, Boolean parameterize, Boolean generateContextAccessors)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsync[TResult](Expression query, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.ExecuteAsync[TResult](Expression expression, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1.GetAsyncEnumerator(CancellationToken cancellationToken)
at System.Runtime.CompilerServices.ConfiguredCancelableAsyncEnumerable`1.GetAsyncEnumerator()
at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.d__67`1.MoveNext()
at Program.d__9.MoveNext() in C:\_temp\Test\Program.cs:line 59

This exception was originally thrown at this call stack:
[External Code]

Inner Exception 1:
ArgumentException: GenericArguments[1], 'System.ReadOnlySpan`1[System.String]', on 'System.Linq.Expressions.Interpreter.FuncCallInstruction`2[T0,TRet]' violates the constraint of type 'TRet'.

Inner Exception 2:
TypeLoadException: GenericArguments[1], 'System.ReadOnlySpan`1[System.String]', on 'System.Linq.Expressions.Interpreter.FuncCallInstruction`2[T0,TRet]' violates the constraint of type parameter 'TRet'.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post