SQLite on iOS - activa/iridium GitHub Wiki

To use Iridium with SQLite in Xamarin.iOS, you only need to add the Iridium library to your app (available as a Nuget package). No other libraries are required.

Using a SQLite database

The simplest way
var dbName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "my.db";
var dbContext = new SqliteContext(dbName);

// ...

dbContext.CreateTable<Customer>();
//
dbContext.DataSet<Customer>().Save(new Customer { Name = "John" });
//
var johnCustomers = from c in dbContext.DataSet<Customer>()
                    where c.Name.StartsWith("John") 
                    select c;
The better way
public class DbContext : SqliteContext
{
     public DbContext() : base(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "my.db")
     {
     }

     public IDataSet<Customer> Customers {get;set;}
     public IDataSet<Product> Products {get;set;}
}

// ...

var dbContext = new DbContext();
//
dbContext.Customers.Save(new Customer { Name = "John" });
//
var johnCustomers = from c in dbContext.Customers 
                    where c.Name.StartsWith("John") 
                    select c;

You can also set the name of the database file later if you prefer (as long as you set it before the first data access):

public class DbContext : SqliteContext
{
     public IDataSet<Customer> Customers {get;set;}
     public IDataSet<Product> Products {get;set;}
}

// ...

var dbContext = new DbContext();

// ...

dbContext.FileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "my.db");
⚠️ **GitHub.com Fallback** ⚠️