EF CodeFirst CTP5 - 手动删除和创建DB? [英] EF CodeFirst CTP5 - Manually drop and create DB?
本文介绍了EF CodeFirst CTP5 - 手动删除和创建DB?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为了测试目的,我想手动删除并使用EF CodeFirst CTP5重新创建数据库。我如何做到这一点?
For testing purposes I would like to manually be able to drop and recreate a DB using EF CodeFirst CTP5. How would I do this?
推荐答案
可以作为您的上的属性使用DbDatabase DbContext 对象提供了一组直接使用数据库的方法。您可以使用创建和删除方法:
The DbDatabase class available as a property on your DbContext object offers a set of methods for directly working with database. You can use the Create and Delete method for this matter:
using (var context = new YourContext())
{
context.Database.Delete();
context.Database.Create();
// Or
context.Database.CreateIfNotExists();
}
这篇关于EF CodeFirst CTP5 - 手动删除和创建DB?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文