实体框架使用的最佳方法 [英] Entity Framework best approach to used

查看:68
本文介绍了实体框架使用的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Entity框架开发MVC 4 Ecommerse应用程序,我的数据库是MYSql。

请告诉我哪个是开发项目的最佳选择



1.Code First

2.DataBase First

3.Model First

I want to develope MVC 4 Ecommerse Application using Entity framework and my database is MYSql .
Please tell me which one is best options to develope my project

1.Code First
2.DataBase First
3.Model First

推荐答案

1。代码优先

在Code First方法中,我们首先关注域设计或实体/ POCO类,并根据我们的模型要求创建类。我们没有应用程序的数据库,而是在定义域之后自动从代码创建数据库。

无论如何,如果您是C#开发人员,您不是数据库方面的专家,只关注您的模型/类创建。 EntityFramework将为您创建和管理数据库带来麻烦。



2.数据库优先

满足想要派生的开发人员的需求来自现有数据库的域模型,数据库第一种方法提供了一组建模工具,用于生成域模型,验证域模型,并基于存储(数据库)模型创建持久类。



3.模型第一

使用模型第一种方法,您可以在设计师中设计模型。或者您可以简单地定义类,让EF使用那些 - 首先称为代码。同样在这种方法中,EntityFramework将为您创建和管理数据库和类带来头痛。



结束这一点很清楚如果您对数据库有良好的指令并已经创建数据库结构然后你可以先选择数据库,另一方面你有很好的命令oop和编码,并希望通过设计模型做任何事情然后选择Code第一种方法,如果你想创建非常简单的应用程序和简单的数据库类型没有任何类模型或数据库,那么你可以先选择模型。
1. Code first
In the Code First approach, we focus on the domain design or entities/POCO classes first and create classes as per our model requirement. We do not have the database of the application, rather we create database automatically from code after defining our domain.
No matter, you are not an expert in database, if you are a C# developer, just focus on your model/class creation. EntityFramework will take headache of creating and managing database for you.

2. Database first
To meet the needs of developers who want to derive a domain model from an existing database, database first approach provides a set of modeling tools that generate a domain model, validate a domain model, and create persistent classes based on the storage (database) model.

3. Model first
With the model first approach, you can design a model in a designer. Or you can simply define classes and let EF work with those—referred to as code first. Also in that approach EntityFramework will take headache of creating and managing database and classes for you.

End of the point this is clear if you have good command on database and already created database structure then you can choose database first, in other hand you have good command over the oop and coding and want to do everything by design model then choose Code first approach, and if you want to create very simple application and simple kind of database without any class model or database then you can choose model first.


你好Shailesh,



查看决策树 在这里给出(由Bahador Izadpanah回答):

http: //stackoverflow.com/questions/5446316/code-first-vs-model-database-first [ ^ ]



和Julie Lerman关于MSDN的文章:

https://msdn.microsoft.com/en-us/magazine/hh148150.aspx [ ^ ]



谢谢。
Hi Shailesh,

Have a look on "Decision tree" given here (answered by Bahador Izadpanah):
http://stackoverflow.com/questions/5446316/code-first-vs-model-database-first[^]

and an article on MSDN by Julie Lerman:
https://msdn.microsoft.com/en-us/magazine/hh148150.aspx[^]

Thanks.


这篇关于实体框架使用的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆