-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add FK constraint checking to the in-memory provider #2166
Comments
Triage Discussed (at length 😄) and ultimately decided that enforcing relationships in the data store is a relational thing. Many other data stores are not going to enforce this (i.e. Azure Table Storage). We could build the InMemory store to emulate relational database behavior but we ultimately decided this is not what we want to do. Ultimately you need to test your application against a real database to some extent since even different relational databases behave differently. If you want something closer to a relational database then using SQLite in in-memory mode is an option. |
@rowanmiller and remember that the sqlite engine does not enforce foreign keys unless you run a PRAGMA command |
What about testing for unique indexes? Now that unique indexes have recently been fixed, I tried writing a unit test to validate this using the InMemoryProvider. The InMemoryProvider doesn't appear to throw an exception when I try to violate the contraint. Is the recommendation for enforcing unique constraints are in place also to use SqlLite? |
Based on the semantics of the FK as discussed in #9470 and that these semantics now matter for querying data from the in-memory provider, we think it would now be useful to have the in-memory provider check cosntraints--that is, if an FK has a non-null value, then there must be a principal key with that value. |
I think that would be if the in memory add the validations for unique index and foreign keys, maybe in a memory with validations and other in memory without validations or maybe with a property for in the memory |
this is my workaround for validating indexes
|
so i needed to work around this enough times that i wrapped the workaround in a nuget https://github.com/SimonCropp/EfCore.InMemoryHelpers |
Is this solved? I am using ModelBuilder ApplyConfiguration and one of the options for example:
InMemoryDatabase just ignores this and it is frustrating. I can insert multiple records with the same 'Email' in this case. |
We recommend against using the in-memory provider for testing--see Testing EF Core Applications. While we have no plans to remove the in-memory provider, we will not be adding any new features to this provider because we believe valuable development time is better spent in other areas. When feasible, we plan to still fix regressions in existing behavior. |
Hi, my apologies if this is already covered by any other open/closed issue but I couldn't find any.
It seems that the In-memory provider is not enforcing required foreign key properties and thus acts differently from SQL Server provider. I'm using build 7.0.0-beta5-13171 (latest nightly).
I suppose this is a known issue? Is there a plan/target for fixing it? I believe unit testing is a big use case for using the in-memory provider but with this kind of limitations, its value is diminished (for now).
Here's sample code to demonstrate this:
Context & model:
The text was updated successfully, but these errors were encountered: