All the factory classes provide two kinds of factory methods.
The difference between them is in the lifecycle of the underlying in-memory database bound to the endpoint.
Creates a fake object that relies on an in-memory database instance that lives during the connection object lifecycle. If the connection object is disposed or garbage collected, then the underlying database will be garbage collected too.
The following code instantiates a DbContext object with a fake DbConnection object and adds some data to the fake database.
Then creates another DbContext instance with a newly created fake DbConnection and tries to query the previously added data.
The second DbContext instance is not able to see the entity added by the first DbContext instance.
Creates a fake object that relies on an in-memory database instance that lives during the complete application lifecycle. This method accepts a string argument which identifies the fake database instance that the connection object is bound to.
Let’s change the previous code a little bit by using CreatePersistent method.
The second DbContext instance can see the newly added entity this time because the connection objects are bound to the same database instance. This is possible because they were created with the same identifier.