CodeFirst相对于Database First的优势是什么?
我正在观看一些有关EF 4.1的视频和教程,但我不了解CodeFirst的任何好处(除了某些情况,如果DB的3-4表很小,并且我懒于先创建DB).
I was watching some videos and tutorials for EF 4.1, and I do not understand any benefit of CodeFirst (except some if DB is very small 3-4 tables and I am lazy for creating DB first).
到目前为止,到目前为止,最好的方法通常是在某种数据库编辑器中创建数据库,这肯定比在实体模型中编辑和EF能够拾取所有关系并正确创建关联要快.我知道命名约定等方面存在挑战,但是我觉得管理代码优先"非常混乱,因为一切看起来都像代码,而且代码也太多.
Mostly, the best approach so far is to create Database in some sort of Database editor, which is sure faster then editing in the Entity Model and EF picks up every relationships and creates associations correctly. I know there are challenges in naming convention etc, but I feel its very confusing to manage Code First as everything looks like code and its too much to code either.
CodeFirst可以做什么,而Db首先不能做什么?
What is it that CodeFirst can do and Db first cannot?
CodeFirst无法执行DB First无法执行的任何操作.归根结底,他们俩都在使用实体框架.
CodeFirst cannot do anything that DB first cannot. At the end of the day they are both using the Entity Framework.
使用代码优先的主要优点是:
The main advantages of using codefirst are:
- 开发速度-您不必担心只是开始编码就可以创建数据库.对于没有大量DBA经验的编程背景的开发人员来说非常有用.它还具有数据库自动更新功能,因此无论您何时更改模型,数据库也会自动更新.
- POCO -该代码非常简洁,不会导致加载大量自动生成的代码.您可以完全控制每个班级.
- 简单-您没有要更新或维护的edmx模型
- Development Speed - You do not have to worry about creating a DB you just start coding. Good for developers coming from a programming background without much DBA experience. It also has automatic database updates so whenever you model changes the DB is also automatically updated.
- POCOs - The code is a lot cleaner you do not end up with loads of auto-generated code. You have full control of each of your classes.
- Simple - you do not have a edmx model to update or maintain
有关更多信息,请参见代码优先与模型/数据库-第一而在代码优先或数据库优先的情况下,如何选择?
For more info see Code-first vs Model/Database-first and here Code-First or Database-First, how to choose?