I need to implement the following pattern: https://msdn.microsoft.com/en-us/library/dn589799.aspx
I read on a book that following:
If you are using Entity Framework 6 (EF 6), the retry logic for transient faults is built in to the framework. When your EF 6 model is in your project, you need to create a new class that derives from DbConfiguration and customizes the execution strategy in the constructor. EF 6 will look for classes that derive from DbConfiguration in your project and use them to provide resiliency. To set this, add a new Class file to your project and add using statements for System.Data.Entity and System.Data.Entity.SqlServer.
The code is as follows:
public class EFConfiguration : DbConfiguration
{
public EFConfiguration()
{
this.SetExecutionStrategy("System.Data.SqlClient", () => new SqlAzureExecutionStrategy());
}
}
However I am not sure how to implement it on my code:
public class AppDataContext : DbContext
{
public AppDataContext() : base("AppDataContext")
{
}
public DbSet<Module> Modulos { get; set; }
public DbSet<Empresa> Empresas { get; set; }
public DbSet<Entidad> Entidades { get; set; }
public DbSet<Propiedad> Propiedades { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
}
public class AppDataContextInitializer : System.Data.Entity.DropCreateDatabaseAlways<AppDataContext>
{
protected override void Seed(AppDataContext context)
{
#region Seed Modules
context.Modulos.Add(new Module() { Id = 1, ModuleName = "Contabilidad", FontAwesomeClass = "fa-ambulance" });
context.Modulos.Add(new Module() { Id = 2, ModuleName = "Recursos Humanos", FontAwesomeClass = "fa-heartbeat" });
context.Modulos.Add(new Module() { Id = 3, ModuleName = "Inventario", FontAwesomeClass = "fa-anchor" });
context.Modulos.Add(new Module() { Id = 3, ModuleName = "Produccion", FontAwesomeClass = "fa-binoculars" });
context.Modulos.Add(new Module() { Id = 3, ModuleName = "Ventas", FontAwesomeClass = "fa-coffee" });
context.Modulos.Add(new Module() { Id = 3, ModuleName = "Compras", FontAwesomeClass = "fa-calendar-o" });
context.Modulos.Add(new Module() { Id = 3, ModuleName = "Cotizaciones", FontAwesomeClass = "fa-building" });
#endregion
#region Seed Empresas
context.Empresas.Add(new Empresa() { Id = 1,
Nombre = "XYA",
NIT = "900854343",
NombreRepresentanteLegal = "Carla Peresz",
TelefonoRepresentanteLegal = "123",
NombreContacto = " Esteban Andres",
TelefonoContacto = "123"
});
#endregion
#region Seed Entidades
context.Entidades.Add(new Entidad()
{
Id = 1,
Nombre = "Empresa",
Propiedades = new List<Propiedad>()
{
new Propiedad()
{
Codigo="01",
Nombre="Twitter",
TipoDeDatos="Texto"
}
}
});
#endregion
#region Seed Propiedad
#endregion
base.Seed(context);
}
}