xamarin.forms - How to use SQLITE async extensions within a transaction in a Xamarin Forms PCL? -
i'm trying figure out how, in transaction, use sqlite async extension methods such insertorreplacewithchildrenasync (nuget twincoders).
on startup in xamarin.forms pcl, have:
using xamarin.forms; using sqlite.net; using sqlite.net.async; using sqlitenetextensions; using sqlitenetextensionsasync.extensions; ... ... static sqliteasyncconnection db; db = dependencyservice.get<isqlite> ().getasyncconnection ();
as side note, additionally following, don't, having read unwise mix sync , async database operations:
dbsync = dependencyservice.get<isqlite> ().getsyncconnection ();
my first idea was:
await db.runintransactionasync ( ( sqlite.net.async.sqliteasyncconnection tran ) => { tran.insertall withchildren ( ...); ... }
but gets following warning @ build time:
... runintransactionasync(action<sqliteasyncconnection> ... cause deadlock if .... use runintransactionasync(action<sqliteconnection>) instead.
if use synchronous methods within transaction, following work:
await db.runintransactionasync ( ( sqlite.net.sqliteconnection tran ) => { var x = new x(); tran.insert (x); var y = new y(); tran.insert (y); });
however, tran has regular synchronous methods, , not offer of extension methods such insertorreplacewithchildren.
my searches have not turned information on how access extension methods within transaction.
if obtain dbsync above, dbsync not offer extension methods. maybe has problem. in companion ios project have:
using xamarin.forms; using sqlite.net; using sqlite.net.async; using sqlite.net.platform.xamarinios; ... ... public class conn : xyz.isqlite { ... public sqlite.net.sqliteconnection getsyncconnection () { ... } public sqliteasyncconnection getasyncconnection() { ... } ... }
it appear adding async packages somehow blocks synchronous extensions. adding pcl helper class library has synchronous sqlite.net , synchronous extensions, , fetching sync connection there, did not help.
guillermo gutiƩrrez doral resolved follows:
"due nature of sqlite.net async, synchronous operations supported inside transaction. otherwise, failed operation between begin , end of transaction may make transaction rollback when operation not inside transaction block. not sqlite-net extensions limitation, sqlite.net one. can still access sqlite-net extensions synchronous operations, insertorreplacewithchildren."
https://bitbucket.org/twincoders/sqlite-net-extensions/issue/61/async-extension-methods-within-a
Comments
Post a Comment