简体   繁体   English

EF Core 异步客户端评估

[英]EF Core async client side evaluation

Working with net5.0 .使用net5.0 So I have this query:所以我有这个查询:

context.DbSet
  .Where() // server side
  .AsEnumerable()
  .Where() // can't be translated to SQL so client side
  .ToList();

So how can we achieve an async variant of this?那么我们如何实现这个的异步变体呢? I would assume it would work like this:我会假设它会像这样工作:

await context.DbSet
  .Where() // server side
  .AsAsyncEnumerable()
  .Where() // can't be translated to SQL so client side
  .ToListAsync();

But that doesn't work.但这不起作用。 What is the right approach?什么是正确的方法?

As mentioned in the Explicit client evaluation section of the EF Core documentation, the EF Core team vision is that如 EF Core 文档的显式客户端评估部分所述,EF Core 团队的愿景是

If you are using AsAsyncEnumerable and want to compose the query further on client side then you can use System.Interactive.Async library which defines operators for async enumerables.如果您正在使用AsAsyncEnumerable并希望在客户端进一步编写查询,那么您可以使用System.Interactive.Async库,它定义了异步枚举的运算符。 For more information, see client side linq operators .有关详细信息,请参阅客户端 linq 运算符

So by idea you need to install that package and use因此,您需要安装 package 并使用

await context.DbSet
  .Where() // server side
  .AsAsyncEnumerable()
  .Where(...) // this is provided by System.Interactive.Async
  .ToList(); // as well this

Just please note that there is some method naming clash when you reference both packages ( System.Interactive.Async and Microsoft.EntityFrameworkCore , because EF Core DbSet<T> implements both IEnumerable<T> and IAsyncEnumerable<T> , which makes some extension method calls ambiguous), so you might start getting compile time errors.请注意,当您引用两个包( System.Interactive.AsyncMicrosoft.EntityFrameworkCore时,存在一些方法命名冲突,因为 EF Core DbSet<T>实现了IEnumerable<T>IAsyncEnumerable<T> ,这使得一些扩展方法调用模棱两可),因此您可能会开始遇到编译时错误。 There are open issues in their GitHub issue trackers, but neither team is willing to fix them saying that the problem is caused by the other.他们的 GitHub 问题跟踪器中存在未解决的问题,但两个团队都不愿意修复他们说问题是由另一个问题引起的。 One of the drawbacks of the open source policy utilized recently by Microsoft.微软最近使用的开源政策的缺点之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 带有布尔异步调用的 EF Core 3.1 客户端评估问题 - EF Core 3.1 Client Side Evaluation Issue With Boolean Async Call EF Core Any in Any客户端评估 - EF Core Any in Any client side evaluation EF Core 3.1 - 如何使用 InMemory Provider 检测客户端评估错误? - EF Core 3.1 - how to detect client-side evaluation errors using the InMemory Provider? EF core 3嵌套组通过限制客户端评估后 - EF core 3 nested group by after restricting client evaluation 避免客户端评估,同时在 EF Core 3 中保持干净的代码 - Avoid client evaluation while maintain clean code in EF Core 3 客户端评估 - Client side evaluation 当最上面的投影包含方法调用时,EF Core 客户端评估不起作用 - EF Core client evaluation doesn't work, when top most projection contains method call EF Core 3.x - 简单 LINQ with Include 无法翻译,客户评价 - EF Core 3.x - simple LINQ with Include can not be translated, client evaluation 如何修改基于表达式的过滤器以避免在 Entity Framework Core 3.0 中进行客户端评估 - How to modify expression-based filters to avoid client-side evaluation in Entity Framework Core 3.0 如何确定 EF 核心中的自定义服务器评估? - How to determine custom server evaluation in EF core?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM