Ivo*_*gel 14 c# in-memory-database entity-framework-core .net-7.0 ef-core-7.0
我正在使用新的 EF 7ExecuteDelete和ExecuteUpdate功能,它们非常棒。但是当我尝试为使用它们的函数编写单元测试时,这些测试崩溃了。
我在 .NET Core 7、7.0.1Microsoft.EntityFrameWorkCore.InMemory和 Xunit 2.4.2上使用 EF 7.0.1
[Fact]
public async Task DeleteAccountAsync__Success()
{
var accountId = Guid.Parse("52ff9d4e-efb9-4b51-b5e7-1734d10187f7");
// CRASH
_context.Accounts
.Where(p => p.AccountId == accountId)
.ExecuteDelete();
}
private void SeedDataBase()
{
var a1 = new Account
{
AccountId = Guid.Parse("52ff9d4e-efb9-4b51-b5e7-1734d10187f7"),
};
var a2 = new Account
{
AccountId = Guid.Parse("d5c38300-0de6-4118-8d01-6bc94842d4b5"),
};
_context.Accounts.AddRange(a1, a2);
_context.SaveChanges();
}
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
消息“无法翻译 LINQ 表达式 'DbSet()\n .Where(a => a.AccountId == __accountId_0)\n .ExecuteDelete()'。请以可翻译的形式重写查询,或者切换通过插入对“AsEnumerable”、“AsAsyncEnumerable”、“ToList”或“ToListAsync”的调用来显式进行客户端评估。有关详细信息,请参阅 https://go.microsoft.com/fwlink/?linkid=2101038。
| 归档时间: |
|
| 查看次数: |
4444 次 |
| 最近记录: |