Advantages and disadvantages of LINQ to SQL integrated database language

Source: Internet
Author: User
Tags net domain

1, LINQ to SQL benefits

Before LINQ to SQL is launched, we just form a string of SQL statements, and then, Pass ado.net to SQL Server, returning the result set. The flaw here is that if you have a problem with the SQL statement, you only know it at runtime. And not everyone knows the database. LINQ to SQL is available in all projects that revolve around data. Especially when you are missing an expert on SQL Server in your project, the powerful features of LINQ to SQL Help us quickly complete the project. The introduction of LINQ to SQL is to let everyone out of the cumbersome technical details, more attention to the logic of the project. The advent of linqto SQL greatly reduces the Men Yuan of database application development, which is essentially a data access layer for you, which is bound to speed up the development of database applications. LINQ to SQL frees many programmers to put more effort into business logic and code rather than databases. For beginners, LINQ to SQL allows them to quickly enter the field of database application development, saving training costs.

The implementation of LINQ to SQL is based on ado.net and c#2.0. It translates the SQL statement automatically and creates the result set as an object and returns. Here we can see that the SQL statements sent to the SQL Server side are generated automatically by LINQ to SQL. This is no doubt a boon to those who do not know SQL. Second, LINQ to SQL statements are checked during compilation. Rather than run-time checks. In this way, there is a problem and can be changed in time, rather than at runtime to discover the problem. Third, LINQ to SQL is manipulated for objects and more in line with today's OO calls.

Before LINQ to SQL, there was a hibernate in the Java realm, with NHibernate technology in the net domain to implement object/relational persistence and query services. Compared with nhibernate, it has those advantages. First, the innuendo code is generated automatically. VS2008 provides the SQLMetal and Ordesigner two tools to complete this step. And in NHibernate, you have to write them by hand. Second, there are more options for insinuating code. NHibernate can only configure the information of the database in one XML, and LINQ to SQL has two ways, one is put into XML, we are called EXTERNL Mapping, and one is in the form of attribute, in each property. Of course, I did not use the NHibernate, only from the data to get these messages, so can not give more comparison.

2. The disadvantages of LINQ to SQL

A long time ago, a netizen asked such a question. He had a DataView in the interface, which contained columns, and then he checked the column and sorted it by column. The parameter returned is the name of the column. Then ask me how to use the dlinq to achieve.

In the previous era of stitching up SQL statements, this was simple, an "order by" + string, which would be sorted by whatever row you wanted. And now DLinq is a property of an object that is no longer possible to splice. The answer I gave him was this.

The following is a reference fragment:

private void Methods (string orderId)
{
var q = db. Customers.select (C=>C);
switch (orderId)
{Case
"ID":
q = Q.orderby (c=>c.id);
Break Case
"Name":
q = Q.orderby (c=>c.name);
Break
default: Break
;
}
var result = Q.tolist ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.