Advertisement
Intermediate .NET MAUI, Local Storage & Data

How do you use SQLite for local relational data in MAUI?

Short answer

Add the sqlite-net-pcl (or Microsoft.Data.Sqlite) package, create a database file path under FileSystem.AppDataDirectory, define models with attributes, and use an SQLiteAsyncConnection to create tables and run async CRUD. It's the standard choice for structured offline data.

Save .NET MAUI mock interview
Advertisement
AModel answer
Add the sqlite-net-pcl (or Microsoft.Data.Sqlite) package, create a database file path under FileSystem.AppDataDirectory, define models with attributes, and use an SQLiteAsyncConnection to create tables and run async CRUD. It's the standard choice for structured offline data.
var db = new SQLiteAsyncConnection(
    Path.Combine(FileSystem.AppDataDirectory, "app.db3"));
await db.CreateTableAsync<Note>();
await db.InsertAsync(new Note { Text = "Hello" });
var notes = await db.Table<Note>().ToListAsync();
Real-world example
A note-taking app stores entries in SQLite so they're available fully offline and queryable.
Likely follow-ups
  • Where should the db file live? | sqlite-net vs Microsoft.Data.Sqlite?
Related topics