ADO.NET or Linq to SQL?

I am creating a forum and it has 4 tables: users, topics, comments, topics.

I established a connection and pages. I started using the ADO.net method to insert data and select data. But then I discovered that to perform more complex manipulations I need to know SQL. So I was looking for another way, and I found that I could open Visual Studio 2010, add the Linq file to SQL that the relational object designer created. I read about how to write code, and I saw that I just needed to use a using statement with a DataContext tag with simple code to update, add and delete rows in tables.

I wanted to know what are the advantages of using one query method over another?

+1
source share
5 answers

LINQ to SQL is part of the ADO.NET technology family. It is based on the services provided by the ADO.NET provider model. Therefore, you can mix LINQ to SQL with existing ADO.NET applications and migrate your current ADO.NET solutions to LINQ to SQL. The following figure shows a high-level view of the relationship.

enter image description here


Refer to the following:

ADO.NET and LINQ to SQL

Advantages and disadvantages of LINQ

LINQ to SQL performance versus regular stored procedure

LINQ-to-SQL and stored procedures

+3
source

ADO.NET gives you a low level of control over your requests. If query speed is important, this is where you want to be. If speed is not very important, but the rapid development and relational model of an object, LINQ to SQL is a safe bet.

I would recommend Linq for SQL through ADO.NET.

  • Development is fast, and thinking in ORM mode is natural.
  • If your queries are too slow, using the .ExecuteQuery method will allow you to pass in the sql query that you optimized as if you were doing it using the ADO.NET method. I have had great success with Linq to Sql.

I would also look at the Entity Framework. This gives you more control over your objects and how they are implemented, used, and processed than Linq.

+5
source

LINQ to SQL is great for generating a lot of plumbing code for you. But this is basically the same as using directly ADO.NET/SQL. To perform more complex data manipulations in LINQ to SQL, you need to know how to write complex joins in LINQ in the same way as in SQL.

Look at the Entity Framework - this can give you the higher level of abstraction you are looking for.

+2
source

In addition to the Entity Framework, you can take a look at NHibernate (another .net Relation Mapper). It was longer than EF, so it is a bit more mature, but Microsoft is not designed if it matters to you.

+1
source

Both are at different levels of abstraction. ADO.NET is the lowest level of data access in .NET. Everything will be built on it.

Each abstraction should enable you to express higher-level concepts through lower-level concepts.

If I look like a philosopher, because he is on Friday.

0
source

Source: https://habr.com/ru/post/1401582/


All Articles