To use Iridium with SQLite in Xamarin.iOS or Xamarin.Android, the package is required in addition to the base Iridium package.
var dataFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal); var dbName = Path.Combine(dataFolder, "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;
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" );