Linq to Sql、Linq、Typed Datasets、ADO.NET 之间的区别

Difference between Linq to Sql, Linq, Typed Datasets, ADO.NET(Linq to Sql、Linq、Typed Datasets、ADO.NET 之间的区别)
本文介绍了Linq to Sql、Linq、Typed Datasets、ADO.NET 之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我一直在想这个问题.现在好像有很多方法我不知道什么时候用什么?或者,如果甚至有一点可以学习它们.就像我不知道他们是否基本上做所有相同的事情,只是基本上坚持一个,直到你掌握它,然后再看看其他的.

I been wondering about this for a while. It seems like there are so many ways now I don't know when to use what? Or if there is even a point to learn them. Like I don't know if they basically do all the same things and just basically stick with one till you master it then maybe look at other ones.

所以当我参加 ASP.NET 课程时,这是我计划的一部分.

So when I was taking an ASP.NET course that was part of my program.

我们首先喜欢 ADO.NET,我们只是在代码中使用 SQL 语句编写所有内容.然后我们转向了 3 层架构.这是通过创建类似的类并具有返回内容的数据集来完成的.

We first did like ADO.NET where we just wrote everything with SQL statements in the code. We then moved onto a 3 tier architecture. This was done by making like classes and having datasets that return stuff.

SQL 是在课堂上写的.我个人从来没有真正喜欢过这种方式,因为我总是觉得尝试正确引用很烦人,而且总体上不喜欢它.

The SQL was written in the class. I personally never really liked this way since I always found it annoying with trying to get the quotes right and just overall did not like it.

然后我在 Asp.net 站点上找到了我非常喜欢的 3 层拱形教程.他们使用类型化数据集.您将数据集文件添加到您的 DAL 文件夹,然后您将通过 GUI 制作表格适配器和内容.然后你会在这些 GUI 中编写你的代码,我发现它是完美的解决方案,因为现在我的 SQL 代码远离我的代码,我不必担心引号和所有那些不正确的东西或关闭连接和东西加上它甚至还有一个 SQL GUI 生成器!

I then found on the Asp.net site their tutorial of 3 tier arch that I really liked. They where using typed data sets. You add the dataset file to you DAL folder and you would make table adapters and stuff through the GUI. You would then write you code in these GUI, I found it the perfect solution since now my SQL code was away from my code and I did not have to worry about quotes and all that stuff not being right or closing the connections and stuff plus it even had a SQL GUI builder!

然后我只需在 BLL 文件夹中创建文件并创建一个属性来获取表适配器并编写我的业务层逻辑.

Then I would just make file in the BLL folder and make a property to grab the table adapter and write my business layer logic.

我唯一不喜欢的是因为它是输入的,如果我的东西试图返回一些新行,它会变得很生气.

The only thing I did not like was since it was typed if my stuff tried to return some new rows it would get mad.

所以当我必须连接表时,我通常不得不制作一个新的表适配器.

So when I had to join tables I usually had to make a new table adapter.

现在似乎有这么多.

  • Linq -> 有人说会取代 ADO.NET,有人说不会.
  • Linq 到 sql
  • ado.net

我不确定这是否是全部,可能不是.

I am not sure if that is all of them probably not.

在写这篇文章之前,我快速检查了一下 linq to sql 是关于什么的,并看到一些帖子说 MS 正在扼杀它.他们从 2008 年开始,所以我不知道这是否属实,但我注意到几乎所有 MVC 书籍都使用 linq to sql,所以我认为不是.

Before writing this post I did a quick check to see what linq to sql was about and saw some posts saying that MS was killing it off. They where from like 2008 so I don't know if this is true or not but I noticed that almost all the MVC books use like linq to sql so I don't think it is.

那么是否值得切换到另一种类型的数据集然后键入数据集?还是分别用于不同的情况?

So is it worth switching to something a different one then typed datasets? Or are each used for different situations?

推荐答案

LINQ 本身只是融入 C# 3.0 的一项基础技术(语言集成查询") - 它无事本身与数据库.LINQ 可用于多种事物 - 数据库、XML、内存中的对象、实体框架实体、Active Directory - 应有尽有.

LINQ by itself is just a base technology ("Language Integrated Query") that's baked into C# 3.0 - it has nothing to do per se with databases. LINQ can be used against a variety of things - databases, XML, objects in memory, Entity Framework entities, Active Directory - you name it.

Linq-To-SQL 是轻量级、直接、仅限 MS-SQLServer 的技术,它允许您将 SQL Server 表轻松、漂亮地用作 .NET 应用程序中的真实对象.它是一个对象关系映射器",可以更轻松地处理数据库.它只是 SQL Server,Microsoft 不会进一步扩展它 - 它也在 .NET 4.0 中可用,但不会再进一步开发.

Linq-To-SQL is the lightweight, straightforward, MS-SQLServer only technology which allows you to use SQL Server tables easily and nicely as real objects in your .NET application. It's a "Object-relational mapper" that makes dealing with databases easier. It's SQL Server only, and Microsoft will not extend it much further - it's available, also in .NET 4.0, but won't be further developed any more.

ADO.NET 是 .NET 中的基本数据访问技术 - 它使您可以访问各种数据存储,关系型和非关系型.这是一项非常基本的技术 - 您以非常低级的原始方式处理数据.

ADO.NET is the base data access technology in .NET - it gives you access to a wide variety of data stores, relational and non-relational. It's the very basic technology - you deal with your data in a very low-level, raw manner.

最重要的是,您有 ADO.NET 数据集,它有点像 Linq-to-SQL,因为它们使处理数据库更容易一些.与 Linq-to-SQL 不同,您不是在 .NET 代码中处理域模型中的对象,而是像处理面向数据库的行和列一样存在于数据库中.它更直接地表示数据库中的内容,它位于较低级别,与您的数据库布局非常紧密地耦合,并且它不像 Linq-To-SQL 对象那样好"且易于使用 - 您处理的是低级别行和列及其值.

On top of that, you have the ADO.NET datasets, which are a bit like Linq-to-SQL in that they make it somewhat easier to deal with databases. Contrary to Linq-to-SQL, you're not dealing with your objects from your domain model in your .NET code, but instead you're dealing with the database-oriented rows and columns just like they exist in the database. It's a more direct representation of what's in the database, it's on a lower level, it's very tightly coupled to your database layout, and it's not as "nice" and easy to use as Linq-To-SQL objects - you deal with lowlevel rows and columns and their values.

如果您现在有选择,并且除了 SQL Server 之外什么都不需要,我强烈建议您查看 Linq-to-SQL - 从原始数据库表到漂亮且易于使用的 .NET 对象的映射.让您的生活更轻松!

If you have the choice right now, and don't need anything but SQL Server, I would highly recommend checking out Linq-to-SQL - the mapping from the raw database tables to nice and easy to use .NET objects really makes your life a whole lot easier!

马克

这篇关于Linq to Sql、Linq、Typed Datasets、ADO.NET 之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Is Unpivot (Not Pivot) functionality available in Linq to SQL? How?(Linq to SQL 中是否提供 Unpivot(非 Pivot)功能?如何?)
How to know if a field is numeric in Linq To SQL(如何在 Linq To SQL 中知道字段是否为数字)
Linq2SQl eager load with multiple DataLoadOptions(具有多个 DataLoadOptions 的 Linq2SQl 急切加载)
Extract sql query from LINQ expressions(从 LINQ 表达式中提取 sql 查询)
LINQ Where in collection clause(LINQ Where in collection 子句)
Orderby() not ordering numbers correctly c#(Orderby() 没有正确排序数字 c#)