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

c# ef-core-2.0 entity-framework-core tdd unit-testing

Question

I'm really excited about in memory feature of EF Core for unit testing. It relieves me of the burden to write dedicated repository, just for the sake of making code unit testable. But merely in memory testing in a collection wont't suffice.

Does EF Core In Memory Provider validates referential constraints?

1
4
6/23/2018 10:04:22 AM

Accepted Answer

Does EF Core In Memory Provider validates referential constraints?

The answer is: No.

InMemory provider is not a replacement for relational database. It is created for testing purpose.

Excerpt from the 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.

The first point spot that any constraint is not validated by the provider.

4
6/23/2018 10:07:41 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow