Skip to content

Instantly share code, notes, and snippets.

@anytizer
Last active June 17, 2022 06:49
Show Gist options
  • Save anytizer/4354b70de8857c25491b8e293dac2f43 to your computer and use it in GitHub Desktop.
Save anytizer/4354b70de8857c25491b8e293dac2f43 to your computer and use it in GitHub Desktop.
C# SQLite Entity Framework
using configs;
using databases.models;
using Microsoft.EntityFrameworkCore;
namespace databases.contexts
{
public class ProjectContext : DbContext
{
public DbSet<CompanyModel>? companies { get; set; }
public DbSet<InvoiceModel>? invoices { get; set; }
public DbSet<ProductModel>? products { get; set; }
public ProjectContext()
{
}
~ProjectContext()
{
this.SaveChanges();
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite(Config.SQLiteDSN());
optionsBuilder.EnableSensitiveDataLogging(true);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
}
}
public void factory_reset()
{
context.Database.ExecuteSqlRaw("DELETE FROM emails;");
context.Database.ExecuteSqlRaw("DELETE FROM users;");
context.Database.ExecuteSqlRaw("DELETE FROM persons;");
context.Database.ExecuteSqlRaw("DELETE FROM persons_temp;");
context.SaveChanges();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment