【问题标题】:Why does a Model First Entity Framework 4.0 model require a database before creation?为什么 Model First Entity Framework 4.0 模型在创建之前需要数据库?
【发布时间】:2010-03-20 04:13:34
【问题描述】:

我正在阅读一篇关于 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 来破坏现有数据库,为什么首先需要现有数据库?

谢谢,

斯科特

【问题讨论】:

    标签: entity-framework-4


    【解决方案1】:

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

    否则你会遇到先有鸡还是先有蛋的问题,因为你不得不这样做。提供一个指向现有数据库的连接字符串,以便能够首先连接到数据库。

    虽然可能有一些选项可以让 EF 生成数据库,但它可能不值得在实现上遇到麻烦。只需将 EF 指向一个现有但为空的数据库即可。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-04
      • 2014-03-22
      • 2011-07-07
      相关资源
      最近更新 更多