Last active
June 17, 2022 06:49
-
-
Save anytizer/4354b70de8857c25491b8e293dac2f43 to your computer and use it in GitHub Desktop.
C# SQLite Entity Framework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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