EF CTP5 自动创建表 SQL Server 2005

发布于 2024-10-14 02:44:21 字数 449 浏览 2 评论 0原文

我一直在使用 EF 4 CTP5 并关注 scottgu 博客文章: http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx

基本上,如果表格丢失,我希望模型为我生成表格。

就我而言,它抱怨有一个无效的数据库对象,那是因为我还没有表。我使用的是 SQL Server 2005,而博客提到了 sqlexpress 或 ce。

我想要创建表的模式,该功能仅适用于 sqlexpress 和 CE 吗?

提前致谢

I've been using EF 4 CTP5 and was following scottgu blog post: http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx

Basically I would like the model to generate the table for me if it is missing.

In my case it is complaining that there is an invalid database object, that's because I don't have a table yet. I'm using SQL Server 2005, whereas the blog mentions sql express or ce.

I would like the mode to create the table, is that feature only for sql express and CE?

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜未央樱花落 2024-10-21 02:44:21

“基本上,如果表格丢失,我希望模型为我生成表格”

目前,使用 CTP5 不支持这种情况,但在(不久的)将来应该可以做到这样的事情: http://blogs.msdn.com/ b/efdesign/archive/2010/10/22/code-first-database-evolution-aka-migrations.aspx

目前仅支持以下2种初始化策略:

// always recreate the database 
DbDatabase.SetInitializer(new DropCreateDatabaseAlways<MyDbContext>());

或者

// recreate the database if any changes to the model are detected.
DbDatabase.SetInitializer(new DropCreateDatabaseIfModelChanges<MyDbContext>());

还需要注意的是,EF创建了整个数据库,而不仅仅是表,因此您不必自己创建数据库。

"Basically I would like the model to generate the table for me if it is missing"

That scenario is currently not supported using CTP5 however it should be possible to do such a thing in the (near) future: http://blogs.msdn.com/b/efdesign/archive/2010/10/22/code-first-database-evolution-aka-migrations.aspx

Currently only the following 2 initialization strategies are supported:

// always recreate the database 
DbDatabase.SetInitializer(new DropCreateDatabaseAlways<MyDbContext>());

or

// recreate the database if any changes to the model are detected.
DbDatabase.SetInitializer(new DropCreateDatabaseIfModelChanges<MyDbContext>());

It should also be noted that EF creates the whole database, not just the tables, so you don't have to create the database yourself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文