开发者

How to programatically create a database from an ADO.Net Entity Model?

I am using .Net Framework 4.0. I have an entity model (.edmx) and I have a menu option in my program for connecting to an existing database or creating a new one. When the user selects to create a new database, I want to generate the database and schem开发者_C百科a from the entity model. Any idea how to do so?


Don't do it. It will only work on your v1 products and as soon as you'll plan to release v1.1 you'll realize you have no way of upgrading existing deployed databases to the new schema.

Instead, use scripts to create all your objects (including indexes, relations, constraints, everything) and use upgrade scripts to control how to upgrade each schema version to the next version, like described in Version Control and your Database.

A weaker alternative is to have a Visual Studio Database Project in your solution because VSDB projects have upgrade capabilities, although diff based. They allow you to deploy .dbschema files using the vsdbcmd tool and this tool can diff and upgrade an existing schema. You can have the VSDB project output be transformed into the EF model via an build transformation step (is not trivial, but is possible).

Overall, do not fall for the lure of the EF (or Linq) modeling as being the master definition of your schema. You'll pay the bigger price later.


Take a look there : How to: Generate a Database from a Conceptual Model (Entity Data Model Tools)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜