Sunday 23 March 2014

LINQ

Stands for Language Integrated Query. LINQ is a relatively new addition to .NET which makes working with databases much easier.

Before LINQ, programmers would usually create their own set of classes to generate the SQL needed to interact with the database, this took a lot of time and effort. ASP.NET's LINQ classes automatically create the SQL needed to interact with your data making it unnecessary to learn SQL. LINQ also streamlines the development process by removing the need to create your own data access classes.

It is important to note that although it is very easy to create LINQ data classes, they do not automatically update when the structure of a database changes; by structure I mean the design of the database not the data that is held inside it. The only way to update LINQ data classes is to recreate the entire dbml file, you can do this by simply deleting the old file and creating a new one. In theory it is possible to refresh individual items but I have found that this occasionally causes problems that prevent the project from building. For this reason I recommend that you always recreate the entire dbml file if your database structure changes.

Before LINQ, databases were usually accessed using the System.Data.SqlClient namespace of the .NET Library. System.Data.SqlClient is still available but it requires a lot more code to use. This method also requires you to either use Store Procedures or SQL code. LINQ has made System.Data.SqlClient obsolete but you may still see it being used in older projects.

No comments:

Post a Comment