.net core xunit UseInMemoryDatabase 报 The provider for the source IQueryable doesn't implement IDbAsyncQueryProvider. 错误

环境:.net core 在xunit中使用 UseInMemoryDatabase 做单元测试

现象:ef core 使用异步查询方法时报错。

解决参考

1. https://docs.microsoft.com/zh-cn/ef/ef6/fundamentals/testing/mocking?redirectedfrom=MSDN#limitations-of-ef-in-memory-test-doubles

2.其实是不支持异步方法引起的,可以改成同步查询,然后用 Task.FromResult 返回结果。

最终解决方式:

我原来异步方法是来自命名空间 System.Linq.Data,改成Microsoft.EntityFrameworkCore后解决

posted @ 2020-06-04 17:02  富贵东坡  阅读(1027)  评论(0编辑  收藏  举报