orm 和 ADO.net 有什么区别? [英] What is the difference between an orm and ADO.net?

查看:26
本文介绍了orm 和 ADO.net 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在读一本书,它说:如果您将使用 ADO.NET 创建自己的数据访问层来访问您的数据库,那么无论数据模式是否存在,您都会受到的影响最小.如果您是使用 O/RM,您的灵活性将受到您使用的工具的限制".ADO.NET 和任何其他 ORM 之间的主要区别是什么?

I am reading a book and it says : "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". What is the major difference between ADO.NET and any other ORM?

推荐答案

ADO.NET 提供对 SQL Server 等数据源的一致访问和 XML,以及通过 OLE DB 和 ODBC 公开的数据源.数据共享消费者应用程序可以使用 ADO.NET 连接到这些数据源并检索、处理和更新它们所获取的数据包含.

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 将数据访问和数据操作分离成离散的可以单独或串联使用的组件.ADO.NET 包括.NET Framework 数据提供程序,用于连接到数据库,执行命令,并检索结果.这些结果要么被处理直接放置在 ADO.NET DataSet 对象中以便公开以特别的方式向用户提供,结合来自多个源,或在层之间传递.也可以使用 DataSet 对象独立于 .NET Framework 数据提供程序来管理本地数据到应用程序或源自 XML.

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 是一个层,允许您连接到 DB 并使用 SQL 连接、命令、参数对其进行修改.ADO.NET MSDN

ADO.NET is a layer that allows you to connect to DB and modify it using SQL connections, commands, parameters. ADO.NET MSDN

对象关系映射(ORM、O/RM 和 O/R 映射工具)在计算机科学是一种用于转换数据的编程技术在面向对象编程中不兼容的类型系统之间语言.这实际上创建了一个虚拟对象数据库",可以在编程语言中使用.两者都有免费和可用于执行对象关系的商业包映射,尽管一些程序员选择构建自己的 ORM工具.

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 FrameworkNHibernate 是 ORM.这意味着您不通过 SQL 连接、命令、参数进行操作 - ORM 为您完成它并允许以 OOP 方式映射您的数据库结构:您可以使用 C# 中的对象添加、读取、更新、删除数据库中的记录.您只需要正确地将对象映射到 DB.Entity Framework 基于 ADO.NET 构建,内部使用 ADO.NET.SQL 语句由 ORM 生成.ORM

Entity Framework and NHibernate are ORMs. It means that you do not operate by SQL connections, commands, parameters - ORM does it for you and it allows to map your database structure in OOP manner: you can add, read, update, delete records in your DB using objects in C#. You need only map your object to DB correctly. Entity Framework is built on ADO.NET and it uses ADO.NET inside. SQL statements are generated by ORM. ORM

一般来说,不使用 ORM 访问 DB 会更快,但您应该提供更多行代码.如果您想以 OOP 方式操作您的数据库并编写更具可读性的代码,您应该选择 ORM.选择什么取决于您的目的.

Generally, access to DB without ORM is faster, but you should provide more lines of code. If you want to operate your DB in OOP manner and write more readable code you should choose ORM. It depends on your purposes on what to choose.

Micro ORM(Dapper、BLToolkit)允许您编写 SQL 查询并将参数映射到对象属性.总的来说,Micro ORM 的性能比 Full ORM 更好,但 ADO.NET 仍然更快.

There are Micro ORMs (Dapper, BLToolkit) which allows you to write SQL queries and map parameters to object properties. Micro ORMs, in general, have better performance than Full ORMs, but ADO.NET is still faster.

另外,还有一些关于 StackOverflow 的问答:EF vs ADO.NET

Also, there are some questions and answers on StackOverflow: EF vs ADO.NET

这篇关于orm 和 ADO.net 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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