async Task InitializeAsync() throwing error about the SQLite.Create flags when trying to set up SQLite with my Xamarin project
I have been following this tutorial:
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/data-cloud/data/databases
to set up a local db for my application in xamarin. However, I keep experiencing the errors:
'Argument 1: cannot conver from SQLite.CreateFlags to System type'
'Argument 2: cannot convert from System.Type to SQLite.CreateFlags'
Around the following line of code:
async Task InitializeAsync()
{
if(!initialized)
{
if(!Database.TableMappings.Any(m => m.MappedType.Name == typeof(Word).Name))
{
await Database.CreateTableAsync(CreateFlags.None, typeof(Word)).ConfigureAwait(false);
}
initialized = true;
}
}
I am really not sure what I am doing wrong here as I am following the details in the tutorial.
Rest of the code from the same class:
public class WordSetupDatabase
{
static readonly Lazy<SQLiteAsyncConnection> lazyInitializer = new Lazy<SQLiteAsyncConnection>(() =>
{
return new SQLiteAsyncConnection(Constants.DatabasePath, Constants.Flags);
});
static SQLiteAsyncConnection Database => lazyInitializer.Value;
static bool initialized = false;
public WordSetupDatabase()
{
InitializeAsync().SafeFireAndForget(false);
}
async Task InitializeAsync()
{
if(!initialized)
{
if(!Database.TableMappings.Any(m => m.MappedType.Name == typeof(Word).Name))
{
await Database.CreateTableAsync(CreateFlags.None, typeof(Word)).ConfigureAwait(false);
}
initialized = true;
}
}
public Task<List<Word>> GetItemAsync()
{
return Database.Table<Word>().ToListAsync();
}
public Task<int> SaveItemAsync(Word item)
{
if(item.ID != 0)
{
return Database.UpdateAsync(item);
}
else
{
return Database.InsertAsync(item);
}
}
}
}