【发布时间】:2018-01-08 18:23:31
【问题描述】:
当我尝试“连接”多个使用导航属性的 IQueryable where 子句时,我在 Entity Core 1.1.0 中遇到异常。
简单示例(不是我的实际代码):
public List<ProjectSummaryDto> TestRelation(string s)
{
var query = _context.TechnologicallyProject
.WhereIf(! string.IsNullOrWhiteSpace(s), q => q.Document.Title.Contains(s))
.ProjectTo<ProjectSummaryDto>();
return query.ToList(); //Exception Message: must be reducible node
}
堆栈跟踪:
在 System.Linq.Expressions.Expression.ReduceAndCheck() 在 System.Linq.Expressions.Expression.ReduceExtensions() 在 System.Linq.Expressions.Compiler.StackSpiller.RewriteExtensionExpression(表达式 expr, 栈栈) ....
但是,当 Contains(Title) 到 Equlas(id) 发生变化时,它可以正常工作
public List<ProjectSummaryDto> TestRelation(int s)
{
var query = _context.TechnologicallyProject
.WhereIf(s != 0 , q => q.Document.Id.Equals(s))
.ProjectTo<ProjectSummaryDto>();
return query.ToList();
}
【问题讨论】:
-
在每种情况下你传递的都是“s”吗?
标签: c# entity-framework linq