entity-framework-4 - 为什么 Model First Entity Framework 4.0 模型在创建之前需要数据库?

标签 entity-framework-4

我正在阅读一篇关于 Entity Framework 4.0 的文章,其中陈述了以下内容:

"The model's context menu has an option to 'Generate Database Script from
 Model'.  When you select this option you'll find that you do need to point
 to an existing database.  The script won't create the database itself,
 just the schema, which means that you'll need to create the database yourself
 in advance."

如果 EF 4.0 设计器生成 SQL 来破坏现有数据库,为什么首先需要现有数据库?

谢谢,

斯科特

最佳答案

它将为您生成表/索引等。您只需要提供一个现有的、空的数据库。

否则你会遇到先有鸡还是先有蛋的问题,例如提供指向现有数据库的连接字符串,以便能够首先连接到数据库。

虽然可能有一些选项可以让 EF 也生成数据库,但可能不值得为实现带来麻烦。只需将 EF 指向现有但空的数据库。

关于entity-framework-4 - 为什么 Model First Entity Framework 4.0 模型在创建之前需要数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2365452/

相关文章:

.net - WCF数据服务SaveChanges问题

linq - 如何实现与 EF 和 NHibernate 一起使用的工作单元

c# - 无法将自定义值插入标识列 - Entity Framework

c# - 在新实体中加载导航属性的最佳方法

linq - 两个Datacontext之间的关系

c# - 错误 : The ObjectContext instance has been disposed and can no longer be used for operations that require a connection

c# - 如何改进有关 EntityCollections<TEntity> 的代码?

linq - 使用 .NET Framework 4 的动态 LINQ API

.net - 我应该更频繁地处理 EF 上下文吗?