实体框架和代码优先开发
微软发布了Entity Framework 4.0,开发人员可以在其中进行Code First开发。这很好,感谢微软。
我对代码优先开发有一个困惑。我曾研究过 ASP.NET 3.5 SP1 和 Visual Studio 2008 SP1 中的实体框架。我们创建一个数据库模式,并从中创建实体数据模型。这意味着我们正在从数据库创建类模型。我想这就是所谓的数据优先开发。
但是,当我们在 Entity Framework 3.5 SP1 中创建实体数据模型时,有两种选择。第一个是从现有数据库生成,另一个是创建一个空白模型。假设我创建一个空白模型,然后将其映射到数据库。因此,我们首先开发类模型而不考虑数据库模式,然后将其与数据库映射。我的困惑是,这叫做代码优先开发吗?那么为什么社区人员和书籍都说“不可能在 Entity Framework 3.5 SP1 中实现代码优先开发”?
为了解决我的困惑,我需要你的帮助。所以请在这个帖子上回复一下。
谢谢。
Microsoft releases Entity Framework 4.0 and in it developers can do Code First Development. This is fine and thanks to Microsoft.
I have one confution about code first development. I have worked on Entity Framework in ASP.NET 3.5 SP1 and Visual Studio 2008 SP1. In that we create a database schema and from that we create Entity Data Model. That means we are creating our class model from database. I think this is called data first development.
But when we create Entity Data Model in Entity Framework 3.5 SP1 then there are two options. First is Generate from existing database and another is create a blank model. Suppose I create a blank model and then map it to the database. So we first develop the class models without thinking the database schema and then map it with database. My confution is, is it called code first deveopment? Then why the community people and books are saying that 'It is not possible to impliment code first development in Entity Framework 3.5 SP1'?
To solve my confution I need your help. So please give reply on this post.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Code First 自 Entity Framework 4.x 起可用。
因此,您无法从 3.5 SP1 中的代码模型生成数据库。
基本上有 3 种类型:
更多信息:使用实体框架 4 进行代码优先开发
Code First is availabe since Entity Framework 4.x.
So you cant generate a Database from your Code Model in 3.5 SP1.
Basicly there are 3 Types:
More Informations: Code-First Development with Entity Framework 4
实际上这就是所谓的“模型优先”开发。虽然Visual Studio中的默认设计器直接将你的模型转化为代码,但它实际上只是你在设计器中看到的“概念模型”。在您定义属性和关系的地方,设计器会使用“代码生成策略”为您创建 .NET 类。
“新代码优先”方法允许您直接创建 .NET 类,然后它会找出“概念模型”的样子。
Actually this is called "model-first" development. Although the default designer in Visual Studio directly turns your model into code, it is actually just a "conceptual model" you see in the designer. Where you define the properties and relationships, the designer than uses a "Code Generation Strategy" which creates the .NET classes for you.
The "new code-first" approach lets you create the .NET classes directly and it than figures out what the "conceptual model" looks like.
当您创建空白模型然后尝试对域进行建模时,称为“模型优先”。您可以在设计器中直观地设计实体模型。然后它会为您生成关系。
在代码优先中,你没有视觉设计师。您必须自己对这些关系进行编码。所以它被称为
代码优先。
查看此内容以了解更多详细信息
代码优先与模型/数据库优先
When you create a blank model and then trying to model the domain is called
Model First
. you can visually design the entity model in the designer.Then it will genarate the relationships for you.In code first you don't have a visual designer . You have to code the relationships yourself. So it's called
Code First.
Have a look at this for more details
Code-first vs Model/Database-first