
Public async Task SaveItemAsync(TodoItem item) Return await Database.Table().Where(i => i.ID = id).FirstOrDefaultAsync() return await Database.QueryAsync("SELECT * FROM WHERE = 0") Return await Database.Table().Where(t => t.Done).ToListAsync() Public async Task> GetItemsNotDoneAsync() Return await Database.Table().ToListAsync() The following example shows the data manipulation methods in the sample app: public class TodoItemDatabase The SQLite.NET library provides a simple Object Relational Map (ORM) that allows you to store and retrieve objects without writing SQL statements. The TodoItemDatabase class includes methods for the four types of data manipulation: create, read, edit, and delete. Var result = await Database.CreateTableAsync() The TodoItemDatabase uses asynchronous lazy initialization to delay initialization of the database until it's first accessed, with a simple Init method that gets called by each method in the class: public class TodoItemDatabaseĭatabase = new SQLiteAsyncConnection(Constants.DatabasePath, Constants.Flags) The sample app defines a TodoItemDatabase class for this purpose. This class centralizes query logic and simplifies the management of database initialization, making it easier to refactor or expand data operations as the app grows.

Create a database access classĪ database wrapper class abstracts the data access layer from the rest of the app. For more information about SQLiteOpenFlags, see Opening A New Database Connection on. You may need to specify different flags depending on how your database will be used.


Public const string DatabaseFilename = "TodoSQLite.db3" The sample project includes a Constants.cs file that provides common configuration data: public static class Constants
#SQLITE FOREIGN KEY INSTALL#
In addition to sqlite-net-pcl, you temporarily need to install the underlying dependency that exposes SQLite on each platform:Ĭonfiguration data, such as database filename and path, can be stored as constants in your app. (INSERT INTO "main".SQLite.NET is a third-party library that's supported from the praeclarum/sqlite-net repo. Here is an example of the error:įoreign key mismatch - NSF referencing STUDENT These three other tables give me a foreign key error but two other tables work just fine. PRIMARY KEY("last_name","first_name","date_of_birth") My Main Table is: CREATE TABLE "STUDENT" (
