orm 和 ADO.net 有什么区别?
What is the difference between an orm and ADO.net?
我正在看书,上面写着:"if you will create your own data access layer by using ADO.NET for access into you database, you will be minimally affected whether the data schema exists or not. If however you are using an O/RM, your flexibility will be limited by the tool you use"。
ADO.NET 和任何其他 ORM 之间的主要区别是什么?
ADO.NET provides consistent access to data sources such as SQL Server
and XML, and to data sources exposed through OLE DB and ODBC.
Data-sharing consumer applications can use ADO.NET to connect to these
data sources and retrieve, handle, and update the data that they
contain.
ADO.NET separates data access from data manipulation into discrete
components that can be used separately or in tandem. ADO.NET includes
.NET Framework data providers for connecting to a database, executing
commands, and retrieving results. Those results are either processed
directly, placed in an ADO.NET DataSet object in order to be exposed
to the user in an ad hoc manner, combined with data from multiple
sources, or passed between tiers. The DataSet object can also be used
independently of a .NET Framework data provider to manage data local
to the application or sourced from XML.
ADO.NET 是一个允许您连接到数据库并使用 SQL 连接、命令和参数对其进行修改的层。 ADO.NET MSDN
Object-relational mapping (ORM, O/RM, and O/R mapping tool) in
computer science is a programming technique for converting data
between incompatible type systems in object-oriented programming
languages. This creates, in effect, a "virtual object database" that
can be used from within the programming language. There are both free
and commercial packages available that perform object-relational
mapping, although some programmers opt to construct their own ORM
tools.
Entity Framework
和 NHibernate
是 ORM。这意味着您不通过 SQL 连接、命令、参数进行操作 - ORM 为您完成,它允许以 OOP 方式映射您的数据库结构:您可以使用添加、读取、更新、删除数据库中的记录C#中的对象。您只需要将您的对象正确映射到数据库。 Entity Framework
建立在 ADO.NET 之上,它在内部使用 ADO.NET。 SQL 语句由 ORM 生成。 ORM
一般情况下,不使用ORM访问DB会更快,但是你应该提供更多的代码行。如果您想以 OOP 方式操作您的数据库并编写更具可读性的代码,您应该选择 ORM。选择什么要看你的目的。
有微型 ORM(Dapper、BLToolkit)允许您编写 SQL 查询并将参数映射到对象属性。一般而言,微型 ORM 的性能优于完整 ORM,但 ADO.NET 仍然更快。
此外,Whosebug 上还有一些问答:EF vs ADO.NET
- 一路走来,我了解到开发人员讨厌使用
DataSets
和 DataReaders
- .NET 平台定义了许多命名空间,允许您
与关系数据库系统交互。总的来说,
这些命名空间被称为
ADO.NET.
- ORM代表
Object-Relational Mapper
,就是把一个对象映射到一个关系世界。顾名思义builds a relation / maps objects (model) to database objects(tables).
ADO.NET
是将您的应用程序连接到数据库并让开发人员完全控制数据库操作的传统方式,而 ORM
构建在 ADO.NET
之上并使用 ADO.NET
隐含地。
- 简而言之,使用像 NHibernate 这样的 ORM,Entity Framework 让生活更简单,其中对象(模型)的映射由
ORM.
- 当您使用
ORM
时,并非一切都在您手中,因为所有查询都是由 ORM
本身生成的。现在我们不知道这些查询是否优化。
In scenarios where performance of your application is a primary concern & absolutely critical OR in scenarios where you know that your application will grow huge in mere future then it is advisable to use ADO.NET
rather than Entity Framework
because it makes your application heavy.
- 对此的解决方案是
Micro ORM's
,例如 Dapper、BLToolkit。这些提供了开发人员想要的本质 - 一种将数据库操作映射到强类型 类. 的简单方法
- LINQ 在某些方面的支持甚至使它 better.But 这些 Micro-ORM 中的一些的主要优点是它的
raw speed.
至理名言:
Dapper
只是做映射,但你需要编写很多代码,EF
在它上面做了更多,而不仅仅是映射。所以 EF 会很慢。
- 我也可以说纯
ADO.NET
比 Dapper
快, OLEDB
比 ADO.NET
快, ODBC
可以比 OLEDB.
- 所以如果我认真对待性能,我可能会避免任何
ORM.
我正在看书,上面写着:"if you will create your own data access layer by using ADO.NET for access into you database, you will be minimally affected whether the data schema exists or not. If however you are using an O/RM, your flexibility will be limited by the tool you use"。 ADO.NET 和任何其他 ORM 之间的主要区别是什么?
ADO.NET provides consistent access to data sources such as SQL Server and XML, and to data sources exposed through OLE DB and ODBC. Data-sharing consumer applications can use ADO.NET to connect to these data sources and retrieve, handle, and update the data that they contain.
ADO.NET separates data access from data manipulation into discrete components that can be used separately or in tandem. ADO.NET includes .NET Framework data providers for connecting to a database, executing commands, and retrieving results. Those results are either processed directly, placed in an ADO.NET DataSet object in order to be exposed to the user in an ad hoc manner, combined with data from multiple sources, or passed between tiers. The DataSet object can also be used independently of a .NET Framework data provider to manage data local to the application or sourced from XML.
ADO.NET 是一个允许您连接到数据库并使用 SQL 连接、命令和参数对其进行修改的层。 ADO.NET MSDN
Object-relational mapping (ORM, O/RM, and O/R mapping tool) in computer science is a programming technique for converting data between incompatible type systems in object-oriented programming languages. This creates, in effect, a "virtual object database" that can be used from within the programming language. There are both free and commercial packages available that perform object-relational mapping, although some programmers opt to construct their own ORM tools.
Entity Framework
和 NHibernate
是 ORM。这意味着您不通过 SQL 连接、命令、参数进行操作 - ORM 为您完成,它允许以 OOP 方式映射您的数据库结构:您可以使用添加、读取、更新、删除数据库中的记录C#中的对象。您只需要将您的对象正确映射到数据库。 Entity Framework
建立在 ADO.NET 之上,它在内部使用 ADO.NET。 SQL 语句由 ORM 生成。 ORM
一般情况下,不使用ORM访问DB会更快,但是你应该提供更多的代码行。如果您想以 OOP 方式操作您的数据库并编写更具可读性的代码,您应该选择 ORM。选择什么要看你的目的。
有微型 ORM(Dapper、BLToolkit)允许您编写 SQL 查询并将参数映射到对象属性。一般而言,微型 ORM 的性能优于完整 ORM,但 ADO.NET 仍然更快。
此外,Whosebug 上还有一些问答:EF vs ADO.NET
- 一路走来,我了解到开发人员讨厌使用
DataSets
和DataReaders
- .NET 平台定义了许多命名空间,允许您
与关系数据库系统交互。总的来说,
这些命名空间被称为
ADO.NET.
- ORM代表
Object-Relational Mapper
,就是把一个对象映射到一个关系世界。顾名思义builds a relation / maps objects (model) to database objects(tables).
ADO.NET
是将您的应用程序连接到数据库并让开发人员完全控制数据库操作的传统方式,而ORM
构建在ADO.NET
之上并使用ADO.NET
隐含地。- 简而言之,使用像 NHibernate 这样的 ORM,Entity Framework 让生活更简单,其中对象(模型)的映射由
ORM.
- 当您使用
ORM
时,并非一切都在您手中,因为所有查询都是由ORM
本身生成的。现在我们不知道这些查询是否优化。
In scenarios where performance of your application is a primary concern & absolutely critical OR in scenarios where you know that your application will grow huge in mere future then it is advisable to use
ADO.NET
rather thanEntity Framework
because it makes your application heavy.
- 对此的解决方案是
Micro ORM's
,例如 Dapper、BLToolkit。这些提供了开发人员想要的本质 - 一种将数据库操作映射到强类型 类. 的简单方法
- LINQ 在某些方面的支持甚至使它 better.But 这些 Micro-ORM 中的一些的主要优点是它的
raw speed.
至理名言:
Dapper
只是做映射,但你需要编写很多代码,EF
在它上面做了更多,而不仅仅是映射。所以 EF 会很慢。- 我也可以说纯
ADO.NET
比Dapper
快,OLEDB
比ADO.NET
快,ODBC
可以比OLEDB.
- 所以如果我认真对待性能,我可能会避免任何
ORM.