I installed Entity Framework 5.0 RC for Framework 4.0 in my project. But when I try to get data from Views I get error. EF tries creating table for this entity.
If you're using a Code First approach then Entity Framework will build the table for you. It looks like you are not using Code First, so you will have create the table in the database.
Hi @PanagiotisKanavos, as you mentioned, it does not require migration.
Use this on your application startup to turn off database initialization and migrations:
Database.SetInitializer<YourContextType>(null);
If you want to turn off database initialization/migration completely regardless of in which project you're using your Context you can add a static constructor to your context to call the initializer. This ensures that the SetInitializer will be called once prior to the first construction/use of your context.
public class YourContext : DbContext
{
static YourContext()
{
// don't let EF modify the database schema...
Database.SetInitializer<YourContext >(null);
}
public YourContext() : base("name=YourContext")
{}
...
}
However, if you only want to do this in a select few projects, you're better off doing it explicitly via application startup - e.g. during your normal IoC setup, like suggested by Ladislav.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With