我有一個使用Contains()
方法的問題,方法參數來自方法參數。linq中使用方法參數的參數包含
我使用實體框架核心1.1和MySQL連接器版本6.10.0-α。
我有這樣的代碼:
public IEnumerable<Message> search(string content) {
var bla = this.appDbContext.Messages.Where(x => x.Content.Contains("edit")).ToList();
var bla1 = this.appDbContext.Messages.Where(x => x.Content=="edit").ToList();
var bla2 = this.appDbContext.Messages.Where(x => x.Content==content).ToList();
var bla3 = this.appDbContext.Messages.Where(x => x.Content.Contains(content)).ToList();
...
前3行中的作品,
然而,第四行(bla3)返回以下錯誤:
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[0] An unhandled exception has occurred while executing the request System.InvalidOperationException: When called from 'VisitChildren', rewriting a node of type 'System.Linq.Expressions.Expression' must return a non-null value of the same type. Alternatively, override 'VisitChildren' and change it to not visit children of this type.
at System.Linq.Expressions.ExpressionVisitor.VisitAndConvert[T](ReadOnlyCollection'1 nodes, String callerName) at Microsoft.EntityFrameworkCore.Query.Expressions.SqlFunctionExpression.VisitChildren(ExpressionVisitor visitor) at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.ExpressionVisitorBase.VisitExtension(Expression node) at Microsoft.EntityFrameworkCore.Query.Expressions.SqlFunctionExpression.Accept(ExpressionVisitor visitor) at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.ConditionalRemovingExpressionVisitor.Visit(Expression node) at Microsoft.EntityFrameworkCore.Query.Expressions.LikeExpression.VisitChildren(ExpressionVisitor visitor) at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.ExpressionVisitorBase.VisitExtension(Expression node) at Microsoft.EntityFrameworkCore.Query.Expressions.LikeExpression.Accept(ExpressionVisitor visitor) at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.ConditionalRemovingExpressionVisitor.Visit(Expression node) at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitWhereClause(WhereClause whereClause, QueryModel queryModel, Int32 index) at Remotion.Linq.QueryModelVisitorBase.VisitBodyClauses(ObservableCollection'1 bodyClauses, QueryModel queryModel) at Remotion.Linq.QueryModelVisitorBase.VisitQueryModel(QueryModel queryModel) at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitQueryModel(QueryModel queryModel) at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitQueryModel(QueryModel queryModel) at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateQueryExecutor[TResult](QueryModel queryModel) --- End of stack trace from previous location where exception was thrown ---
爲什麼不能我使用Contains()
linq表達式中的方法參數的參數?
我能做些什麼來使用它?
這是一個很好的解決方法,然而,正如你寫的 - 在大數據的情況下,這將填滿內存,並不會很好。 我剛剛寫了一個正式答案,指出這是一個真正的bug,並且實體框架的團隊和mysql連接器團隊都知道它。 – shahaf
很高興知道。感謝您的評論。我應該刪除我的答案嗎? –
我找不到刪除它的原因,這可能會幫助沒有大量數據的人,因此不會有內存問題。謝謝。 – shahaf