Me rindo. He encontrado esto: http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-model-amp-database-first-walkthrough.aspx Y pensó, eso es genial. Así que rápidamente rediseñé mi modelo para aprovechar lo mejor de dos mundos.Modelo Primero con DbContext, falla al inicializar la nueva base de datos
Pero ahora mi modelo falla al crear una nueva base de datos (o al agregar tablas a la existente). consigo este error:
Code generated using the T4 templates for Database First and Model First development may not work correctly if used in Code First mode. To continue using Database First or Model First ensure that the Entity Framework connection string is specified in the config file of executing application. To use these classes, that were generated from Database First or Model First, with Code First add any additional configuration using attributes or the DbModelBuilder API and then remove the code that throws this exception.
A:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
Y ese es mi cadena de conexión:
<add name="ForumContextContainer"
providerName="System.Data.SqlClient"
connectionString="Data Source=.\SQLExpress; Initial Catalog=iForum; Integrated Security=True"/>
Nota. Añadí Initial Catalog más tarde, para probar si iba a funcionar, pero era exactamente lo mismo.
En realidad encontré una forma de cambiar las Plantillas T4. Pero gracias de todos modos, –
@ Łukasz Baran se preocupan por compartir su solución? –
@JoelBeckham Mi problema fue lanzar new UnintentionalCodeFirstException(); en la clase de Entidades. – Saber