从修改数据库停止实体框架 [英] Stop Entity Framework from modifying database
问题描述
我开始玩的code-第一的方针,以实体框架,主要是让我可以在我看来,(否则装饰我的物业,注释显示,现在我要创建一个类这是几乎相同的实体框架生成对我来说,这样我可以添加注释,然后从一个对象中的数据复制到下)的人。
I'm starting to play around with the code-first approach to the entity framework, primarily so that I can decorate my properties with annotations for display in my view (otherwise, right now I have to create a class that is nearly identical to the one that entity framework generated for me just so I can add annotations, and then copy the data from one object to the next).
现在它看起来就像当我开始我的应用程序,它试图创建一个数据库。
Right now it looks like when I start my application it is trying to create a database.
我不希望实体框架为曾经修改我的数据库。不,不是永远。甚至不要尝试。这真的不是那么难修改数据库;我会觉得舒服多了,如果我这样做我自己。设计数据库时,我并不需要一个框架来握住我的手。
I do not want entity framework to ever modify my database. No. Not ever. Don't even try it. It really isn't that hard to modify databases; I would feel much more comfortable if I did that myself. I don't need a framework to hold my hand when designing a database.
我可以告诉框架停止试图修改我的数据库?我很犹豫,现在使用code-首先作为一个事实,即它试图改变我的数据库是相当可怕的。即使是在发展中,我再也不想看到它发生。
Can I tell the framework to stop trying to modify my database? I'm very hesitant to use code-first now as the fact that it's trying to modify my database is rather frightening. Even in development I never want to see it happen.
我是运气不好?
推荐答案
如果你不想EF创建数据库,可以禁用数据库初始化:
If you don't want EF to create your database, you can disable the database initializer:
public class SchoolDBContext: DbContext
{
public SchoolDBContext() : base("SchoolDBConnectionString")
{
//Disable initializer
Database.SetInitializer<SchoolDBContext>(null);
}
public DbSet<Student> Students { get; set; }
public DbSet<Standard> Standards { get; set; }
}
请参阅<一href="http://www.entityframeworktutorial.net/$c$c-first/turn-off-database-initialization-in-$c$c-first.aspx" rel="nofollow">http://www.entityframeworktutorial.net/$c$c-first/turn-off-database-initialization-in-$c$c-first.aspx
这篇关于从修改数据库停止实体框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!