2010-03-02 75 views
3

我閱讀有關實體框架4.0的文章,指出以下:爲什麼模型第一個實體框架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來揍現有的數據庫,爲什麼現有的數據庫首先要求?

感謝,

斯科特

回答

5

它將生成表/索引等你。您只需提供一個現有的空數據庫。

否則,你會碰到雞和雞蛋的問題,因爲你必須例如提供指向現有數據庫的連接字符串,以便能夠首先連接到數據庫。

雖然可能有一些選項讓EF生成數據庫,但它可能不值得實施麻煩。只需在現有的空數據庫上添加EF即可。