TDD:EF Core In Memory Provider 是否验证引用约束?

TDD: Does EF Core In Memory Provider validates referential constraints?

我对 EF Core 用于单元测试的内存功能感到非常兴奋。它减轻了我编写专用存储库的负担,只是为了使代码可单元测试。但仅在集合中进行内存测试是不够的。

Does EF Core In Memory Provider validates referential constraints?

Does EF Core In Memory Provider validates referential constraints?

答案是:没有

InMemory 提供程序不能替代关系数据库。它是为测试目的而创建的。

摘自documenation

InMemory is designed to be a general purpose database for testing, and is not designed to mimic a relational database. Some examples of this include:

  • InMemory will allow you to save data that would violate referential integrity constraints in a relational database.

  • If you use DefaultValueSql(string) for a property in your model, this is a relational database API and will have no effect when running against InMemory.

第一点是提供者未验证任何约束。