【发布时间】:2016-08-29 22:37:19
【问题描述】:
在我的 ASP.NET Core MVC 应用程序中,我在跟踪引用其他 LINQ 查询的 LINQ 查询时遇到上述错误。为了这篇文章的简单起见,为了简洁起见,我在这里修改了代码,因为实际查询太长且太复杂。 问题:错误的可能原因是什么?我应该在哪里进一步调试问题?如果有帮助,错误详细信息如下所示。
视图模型:
public class MyViewModel
{
public string Prop1 { get; set; }
public int Prop2 { get; set; }
}
控制器:
public ActionResult Index()
{
var vm = (from q5 in LINQ_Qry5
join q4 in LINQ_Qry4 on q5.SomeID equals q4.SomeID
select new MyViewModel { Prop1= q5.property1, Prop2 = q4.property2}).ToList();
return View(vm);
}
错误详情:
Message=Operation is not valid due to the current state of the object.
Source=System.Linq.Expressions
StackTrace:
at System.Linq.Expressions.MethodCallExpression2.GetArgument(Int32 index)
at System.Dynamic.Utils.ListArgumentProvider.get_Item(Int32 index)
at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.QueryFlattener.Flatten(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.OptimizeJoinClause(JoinClause joinClause, QueryModel queryModel, Int32 index, Action baseVisitAction, MethodInfo operatorToFlatten, Boolean outerJoin)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitJoinClause(JoinClause joinClause, 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.Internal.SqlServerQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.RelationalEntityQueryableExpressionVisitor.VisitSubQuery(SubQueryExpression expression)
at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.ExpressionVisitorBase.Visit(Expression node)
at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.ReplaceClauseReferences(Expression expression, IQuerySource querySource, Boolean inProjection)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.CompileMainFromClauseExpression(MainFromClause mainFromClause, QueryModel queryModel)
at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitMainFromClause(MainFromClause fromClause, 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.Internal.SqlServerQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateQueryExecutor[TResult](QueryModel queryModel)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
【问题讨论】:
-
这可能是因为生成了大量的控制来为您的视图处理建模。 stackoverflow.com/questions/8832470/…
-
不确定是否有必要,但您的
join没有以下on子句。 -
@Pat 那只是一个错字。感谢您指出 - 我纠正了它。但错误仍然存在。
-
EF 核心?这就是答案。没有意见。转到他们的错误跟踪位置。
-
另一个小而无关紧要的错字,
Prop1和Prop2应该是property1和property2
标签: c# asp.net-mvc linq asp.net-core