gpt4 book ai didi

c# - 方法 'Where' 不能遵循方法 'Select' 或不受支持

转载 作者:行者123 更新时间:2023-11-30 17:05:43 25 4
gpt4 key购买 nike

为什么我得到:

The method 'Where' cannot follow the method 'Select' or is not supported. Try writing the query in terms of supported methods or call the 'AsEnumerable' or 'ToList' method before calling unsupported methods.

...使用 WHERE 子句时,例如调用时:

XrmServiceContext.CreateQuery<Contact>().Project().To<Person>().Where(p => p.FirstName == "John").First();

?

这个有效:

XrmServiceContext.CreateQuery<Contact>().Project().To<Person>().First();

这也有效:

XrmServiceContext.CreateQuery<Contact>().Where(p => p.FirstName == "John").First();

我正在使用 AutoMapper QueryableExtension .

附加信息:

  • 我不想在 Where 子句之前调用 ToList()。我知道它会那样工作。
  • CreateQuery<TEntity>()返回 IQueryable<TEntity> .

最佳答案

这是因为您使用的任何查询提供程序都无法处理此问题。一般情况下不是无效的;事实上,大多数查询提供程序确实支持投影后的过滤。某些查询提供程序根本不像其他查询提供程序那样健壮,或者它们表示的查询模型不如 LINQ 接口(interface)(或两者)灵活/强大。因此,从 C# 编译器的角度来看正确的 LINQ 操作可能仍然无法由查询提供程序翻译,因此它能做的最好的事情就是在运行时抛出异常。

关于c# - 方法 'Where' 不能遵循方法 'Select' 或不受支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16174351/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com