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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With