My recent
Data Points column in MSDN Magazine (May 2011) provided an overview of the differences between the three workflows for creating an Entity Framework model:
1) Reverse engineer and existing database into an EDMX model
2) Create an EDMX model in the designer and generate a database from that
3) Forego a physical model and use your domain classes along with Entity Framework Code First.
After listing the big differences and discussing pros & cons of the different workflows, I presented a diagram to encapsulate the decision making.
A few days before the article became public, I received an email from a developer asking about how to create a model when he had pre-existing classes and a pre-existing database. The obvious answer (in my mind) was to use Code First. Otherwise, he would
have had to try to work out a model that would match his existing classes.
I immediately realized that I did not include that suggestion in the decision tree in the article, so here is that diagram, updated.
The new decisions are in red.
Entity Framework 依赖于业务实体对象的概念模型,称为Entity Data Model(EDM),如何选择创建Model是第一个需要考虑的问题。有3中可选的方法:
- Database First – 首先创建传统的数据库,然后利用数据库的返向工程向导,创建概念模型。
- Model First – 使用可视化的EDM设计器设计EDM,接着根据Model 生成数据库。
- Code First – 编写代表概念模型的类,使用Code First技术过程中,没有可视化的Model类。
如下是选择合适的Entity Framework 开发方法的决策树(Decision Tree):
I know that even after you’ve said that you prefer a visual designer, I’m still recommending that you don’t use it in this case (point back to code first) but believe me, you’ll most likely be happier in that scenario.