First time using SQLite
, opted for SQLite.net-pcl,
I have a PCL
library, that I consume from my UWP
app, my PCL library has the DBContext
class :
public NewspaperDataContext(ISQLitePlatform sqLitePlatform, string applicationPath, string dataBaseName)
{
_sqlConnection = new SQLiteAsyncConnection(()=> new SQLiteConnectionWithLock(sqLitePlatform,
new SQLite.Net.SQLiteConnectionString(Path.Combine(applicationPath, dataBaseName), storeDateTimeAsTicks: false)));
CreateTableAsync(_sqlConnection, typeof(Article)).Result.Wait();
CreateTableAsync(_sqlConnection, typeof(Author)).Result.Wait();
CreateTableAsync(_sqlConnection, typeof(Category)).Result.Wait();
CreateTableAsync(_sqlConnection, typeof(Group)).Result.Wait();
var c = _sqlConnection.Table<Article>();
}
private async Task<Task> CreateTableAsync(SQLiteAsyncConnection asyncConnection, Type table)
{
return asyncConnection.CreateTableAsync<Author>().ContinueWith((results) =>
{
Debug.WriteLine(!results.IsFaulted
? $"Error where creating the {nameof(table)} table !!"
: $"Table {nameof(table)} created sucessfully!");
});
}
I call the NewspaperDataContext
from my UWP app like this :
private async void MainPage_OnLoaded(object sender, RoutedEventArgs e)
{
var n = new NewspaperDataContext(new SQLitePlatformWinRT(), ApplicationData.Current.LocalFolder.Path, "LiberteDB");
}
In the NewspaperDataContext constructor at the line :
var c = _sqlConnection.Table<Article>();
A strange MissingMethodException is thrown saying :
An exception of type 'System.MissingMethodException' occurred in SQLite.Net.Async.dll but was not handled in user code
Additional information: Method not found: 'Void SQLite.Net.SQLiteConnectionString..ctor(System.String, Boolean, SQLite.Net.IBlobSerializer, SQLite.Net.IContractResolver)'.
Couldn't find anything related to this error in the internet, please can someone help.
NewspaperDataContext
which must have a return type, but there is no return value in your code. And you call this method somehow like creating a new instance of a class namedNewspaperDataContext
. If this method is void kind, can you please try to call this method with this codeNewspaperDataContext(new SQLitePlatformWinRT(), ApplicationData.Current.LocalFolder.Path, "LiberteDB");
? – Highhandedvar n = NewspaperDataContext(new SQLitePlatformWinRT(), ApplicationData.Current.LocalFolder.Path, "LiberteDB");
? Sorry if I misunderstand yourNewspaperDataContext
method. But I think the problem may come with how you call this method. – Highhanded