I am very new to SQLite and the very first thing I have noticed (coming from MS SQL Server) is that, while developing the app, if I change my model by any ways (or if I add brand new model), my app will crash when trying to add values to this non-existing table.
When I was working with EF and MS SQL and I added e.g. new model (which should result in adding new database table), then if it has recognized that the table has not yet been created, it will create on for you.
Is there a switch that I need to call, when working with the SQLite, which would automatically create/update tables based on my models, or do I need to do it manually?
If there is no switch, then my question would be, is there a way how to programatically create/update all tables based on the latest models in my application?
I am using Repository Pattern when working with the database, but here is a simple example of how my DatabaseRepository looks like:
public class RepositoryContext : DbContext
{
public RepositoryContext() : base("name=RepositoryContext")
{
}
public virtual DbSet<Employee> Employees { get; set; }
public virtual DbSet<Equipment> Furniture { get; set; }
}
and Unit of Work:
public class UnitOfWork : IUnitOfWork
{
private readonly RepositoryContext _context;
public IEmployeeRepository Employees { get; set; }
public UnitOfWork(RepositoryContext context)
{
_context = context;
Employees = new EmployeeRepository(_context);
}
public int Complete()
{
return _context.SaveChanges();
}
public void Dispose()
{
_context.Dispose();
}
}
Aucun commentaire:
Enregistrer un commentaire