Database.BeginTransaction() throwing on InMemory Repository
See original GitHub issueI have a working code for EF7 beta6 with the SQL CE 4.0 data-provider, which uses some transactions inside.
Now I want to unit-test these things. However, when I switch the context options to be in-memory, I get the following exception:
“No service for type ‘Microsoft.Data.Entity.Storage.IRelationalConnection’ has been registered.”
Stack:
at Microsoft.Framework.DependencyInjection.ServiceProviderExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Framework.DependencyInjection.ServiceProviderExtensions.GetRequiredService[T](IServiceProvider provider)
at Microsoft.Data.Entity.Infrastructure.AccessorExtensions.GetService[TService](IAccessor`1 accessor)
at Microsoft.Data.Entity.RelationalDatabaseFacadeExtensions.GetRelationalConnection(DatabaseFacade databaseFacade)
at Microsoft.Data.Entity.RelationalDatabaseFacadeExtensions.BeginTransaction(DatabaseFacade databaseFacade)
Basically, the code to reproduce:
var options = new DbContextOptionsBuilder<BloggingContext>();
options.UseInMemoryDatabase(persist: true);
// options.UseSqlCe(@"Data Source=Blogging.sdf"); --> works fine
using (var x = new BloggingContext(entityOptions))
{
var tx = x.Database.BeginTransaction(); // Fails, when using InMemoryDatabase
x.Blogs.Add(new Blog() {Url = "URL-" + (i*10)});
...
}
What am I doing wrong? Am I missing some context-options?
I would have thought, that these things work out of the box.
Cheers, Harald
Issue Analytics
- State:
- Created 8 years ago
- Reactions:1
- Comments:23 (11 by maintainers)
Top GitHub Comments
I think the exception message tells you everything you need to know 😄…
So here is what your configuration code would look like…
@rowanmiller Thank you so much for pointing that out. I have tested it and it worked like a charm. I am going to my eye doctor after my shift and get a pair of glasses so that I can read the exceptions carefully next time 😄
Again, Thanks for your help!
Regards, Kimwan Ogot