Efcore: Blazor - EntityFrameworkCore - SQLite & Interceptors

Created on 22 Oct 2020  路  15Comments  路  Source: dotnet/efcore

Background

I'm working on a POC of using EF core from inside a Blazor WASM application.
The idea is by using interceptors to capture the connection/command & transactions database calls,
these could then be routed to a instance of the database running as a WASM component

everything is progressing well so far :D

Ask a question

I would like to capture/suppress the creation of the IDbTransaction and/or prevent the call of DbContext.Database.BeginTransaction/Commit/Rollback without the developer having to explicitly configure/disable transactions or simulate/fake a transaction context while running in side a WASM; is this possible with the current interceptors ?

closed-question customer-reported

All 15 comments

Yes, you can intercept transaction management via IDbTransactionInterceptor. Interception docs are in progress, you can see the work-in-progress here, it should help you use it.

Any chance you could share some info on why you need to disable transactions specifically? Which provider are you using (Sqlite), and is there some sort of incompatibility between transactions specifically and WASM?

@roji I'm using the EF Core Sqlite provider and as these need to native library which is not deployed as part of the wasm packages; I'm intercepting the connection and sending the request via javascript interop to the Sqlite WASM libraty; EF core doesn't hold a (real) connection and therefore when EF core Sqlite attempts to call BeginTransaction it reports that a connection is needed; when what is required is a call to the Sqlite WASM to begin the transaction.

Interesting... /cc @bricelam

I wonder if it's possible to somehow support WASM properly via our own Sqlite provider. If not and the situation stays this way, maybe another Sqlite provider?

@roji it be great if the official EF core team Sqlite provider supported the Sqlite WASM as an options IMHO that would be a game changer for Blazor client side having a client database with EF core support

@roji @bricelam this is what inspired me to investigate if I could use the power of EF core interceptors and the Sqlite EF core provider to generate SQL and send over to Sqlite WASM via JSInterop

https://vkbansal.me/blog/sqlite-in-browser-using-webassembly-wasm/

Am closing this as we indeed have a transaction interceptor, and there's nothing more actionable here (but feel free to continue the conversation).

@roji I've tried the transaction interceptor for Sqlite however this isn't firing for/before EF core attempts to create a transaction upon a SaveChanges on the DbContext; and therefore given the connection is closed/faked as the connection held by the Sqlite WASM the EF core provider reports that an open connection is needed to BeginTransaction ?

Any ideas why this would be ?

@3GDXC can you please submit a code sample that shows what you're trying to do, and the error you're seeing?

@roji no problem in the process of doing that; I will put a repo together and provide a link

@roji https://github.com/3GDXC/EfCoreInterceptors shows the connection string issue

@3GDXC did you intend to post that link in #23085? This issue seems to be tracking transaction interception... Let me know and I'll check it out regardless.

@roji the code shows both issues, 1. the connection string 2. the transaction issue (if you supply the second connection string)

I'll try to take a look, but a bit more context on https://github.com/dotnet/efcore/issues/23085#issuecomment-716202850 would probably help understand.

Was this page helpful?
0 / 5 - 0 ratings