The Model.Context.cs file is automatically generated when using Entity Framework Database First.
I have modified the header part of the class to be compatible with a Unit of Work and Repository pattern:
public partial class MyDatabaseContext : DbContext, IDbContext
{
public MyDatabaseContext()
: base("name=MyDatabaseContextEntities")
{
// disable lazy loading for best practices - keeps from accidentaly loading large entity graphs
Configuration.LazyLoadingEnabled = false;
}
// refactored
public new IDbSet<T> Set<T>() where T : class
{
return base.Set<T>();
}
public override int SaveChanges()
{
// this.ApplyStateChanges();
return base.SaveChanges();
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
.
.
.
The issue is that whenever I update the model from the db, obviously, this file gets overwritten.
I've saved the relevant code in a commented out portion of the *.config, and simply copy/paste it back in place whenever the model is updated.
Even though the model is not updated that frequently, I'd like to know if there is a way of preserving this content so I don't have to go through the extra step of copy/pasting.