Reputation: 5088
I am using the in-memory database (using ServiceStack.OrmLite.Sqlite.Windows) for unit testing in servicestack based web API. the method I am trying to test is as follows.
public object Get(object request)
{
using (var db = HostContext.Resolve<IDbConnectionFactory>().OpenDbConnection("ConnectionString"))
{
using (var dbtran = db.OpenTransaction(IsolationLevel.Snapshot))
{
// reading operation from DB
return response;
}
}
}
when I tried to test this method using InmemoryDB connection getting the following Exception because of IsolationLevel.
An exception of type 'System.ArgumentException' occurred in System.Data.SQLite.dll but was not handled in user code
I tried to set the isolation level to snapshot while creating inmemoryDB as follows,
var isolationlevel = IsolationLevel.Snapshot;
db.OpenTransaction().IsolationLevel.Add(isolationlevel);
even after executing this the transaction level is appearing as Serializable and gets the same Exception.
is there any other way to set the Transaction Isolationlevel to Snapshot in in-memory DB?
Upvotes: 1
Views: 994
Reputation: 143284
Sqlite doesn't support creating a IsolationLevel.Snapshot
transaction but SQLite's Isolation and Concurrency docs indicates SQLite exhibits "snapshot isolation" when Write Ahead Logging (WAL) mode is enabled by running "PRAGMA journal_mode=WAL" which you can set in OrmLite with:
db.ExecuteSql("PRAGMA journal_mode=WAL");
Upvotes: 3