简体   繁体   English

ADO.NET还是Linq to SQL?

[英]ADO.NET or Linq to SQL?

I am building a forum, and it has got 4 tables: Users, Threads, Comments, Topics. 我正在建立一个论坛,它有4个表格:Users,Threads,Comments,Topics。

I established the connection and the pages.. I started using the ADO.net way to insert data and select data..but then I found that to make more complex manipulations i need to know SQL. 我建立了连接和页面。.我开始使用ADO.net方式插入数据和选择数据..但是后来我发现,要进行更复杂的操作,我需要了解SQL。 So I was looking for another way, and I found that I can open Visual Studio 2010, add Linq to SQL file that produced object relational designer. 因此,我在寻找另一种方法,发现可以打开Visual Studio 2010,将Linq添加到生成对象关系设计器的SQL文件中。 I read about how to write code, and I saw that I simply need to use a using statement with DataContext object with a simple code to update, add, delete rows in the tables. 我读到有关如何编写代码的信息,并且看到只需要对DataContext对象使用using语句,并使用简单的代码来更新,添加,删除表中的行。

I wanted to know, what are the advantages of using one way of querying over another? 我想知道,使用一种查询方式比另一种查询方式有什么优势?

ADO.NET gives you low level control over your queries. ADO.NET使您可以对查询进行低级控制。 If query speed is going to be of importance, this is where you want to be. 如果查询速度至关重要,这就是您想要的地方。 If you speed is not very important, but rapid development and an Object Relational Model is, LINQ to SQL is a safe bet. 如果速度不是很重要,但是快速开发和对象关系模型很重要,那么LINQ to SQL是一个安全的选择。

I would recommend Linq to SQL over ADO.NET though. 我还是建议通过ADO.NET在SQL上使用Linq。

  1. Development is rapid and thinking in an ORM way is natural. 发展迅速,以ORM方式思考是自然的。
  2. If your queries are too slow, using the .ExecuteQuery method will allow you to pass in a sql statement that you have optimized as if you were doing it in the ADO.NET way. 如果查询太慢,则使用.ExecuteQuery方法将使您传递经过优化的sql语句,就像使用ADO.NET一样。 I have had much success with Linq to Sql. 我对Linq to Sql取得了很大的成功。

Also I would look at Entity Framework. 我还要看看实体框架。 It gives you more control over your objects and how they are implemented, used and handled than Linq. 与Linq相比,它使您可以更好地控制对象以及对象的实现,使用和处理方式。

LINQ to SQL is part of the ADO.NET family of technologies. LINQ to SQL是ADO.NET技术家族的一部分。 It is based on services provided by the ADO.NET provider model. 它基于ADO.NET提供程序模型提供的服务。 You can therefore mix LINQ to SQL code with existing ADO.NET applications and migrate current ADO.NET solutions to LINQ to SQL. 因此,您可以将LINQ to SQL代码与现有ADO.NET应用程序混合使用,并将当前的ADO.NET解决方案迁移到LINQ to SQL。 The following illustration provides a high-level view of the relationship. 下图提供了这种关系的高级视图。

在此处输入图片说明


Refer to the following: 请参阅以下内容:

ADO.NET and LINQ to SQL ADO.NET和LINQ to SQL

Advantages & Disadvantages of LINQ LINQ的优缺点

Performance of LINQ to SQL over Normal Stored procedure LINQ to SQL在常规存储过程上的性能

LINQ-to-SQL and Stored Procedures LINQ-to-SQL和存储过程

LINQ to SQL is great in that it generates alot of the plumbing code for you. LINQ to SQL很棒,因为它可以为您生成大量的管道代码。 But it is basically the same as using straight up ADO.NET/SQL. 但这基本上与直接使用ADO.NET/SQL相同。 To do more complex data manipulation in LINQ to SQL you have to know how write complex joins in LINQ just as you would in SQL. 要在LINQ to SQL中执行更复杂的数据操作,您必须像在SQL中一样,知道如何在LINQ中编写复杂的联接。

Look into Entity Framework - it might give you a higher level of abstraction that you are looking for. 研究实体框架-它可以为您提供所需的更高层次的抽象。

In addition to Entity Framework, you can take a look at NHibernate (another .net Object Relational Mapper). 除了实体框架,您还可以查看NHibernate(另一个.net对象关系映射器)。 It's been around longer than EF so it's a bit more mature, but it isn't developed by Microsoft if that matters to you. 它的存在时间比EF更长,因此已经成熟了一些,但是如果您认为这很重要,它就不是Microsoft开发的。

The two are on different abstraction levels. 两者处于不同的抽象级别。 ADO.NET is the lowest level of data access in .NET. ADO.NET是.NET中最低级别的数据访问。 Anything else will build upon it. 其他任何东西都将基于它。

Every abstraction should give you power to express higher-level concepts at the cost of lower level concepts. 每个抽象都应使您能够以较低级别的概念为代价来表达较高级别的概念。

If I sound like a philosopher it's because it's Friday. 如果我听起来像哲学家,那是因为今天是星期五。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM