Microsoft Language Integrated Query (LINQ) for SQL aka LINQ to SQLIntroduction: This article is about LINQ (Language Integrated Query), one of the funniest concepts and features in .NET programming. LINQ makes querying data a unique programming concept in .NET. Querying data can be done from XML (LINQ to highly extensible and allows developers to create custom data providers to access data. For example. LINQ to Amazon, LINQ to Excel, LINQ to Javascript etc. The scope of this article is limited to LINQ to SQL. This is the use of LINQ to access data from database, especially from Microsoft SQL Server. Why LINQ Many developers need to use two or more programming languages: a high-level language for the business logic and presentation layers (such as Visual C# or Visual Basic) and a query language for interacting with the database (such as Transact-SQL, P-SQL). This requires the developer to be proficient in several languages to be effective. For example, an application that uses a data access API to query a database specifies the query as a literal string using quotation marks, such as "select * from product". This query string is not readable to the compiler and is not checked for errors, such as invalid syntax or whether the columns or rows it references actually exist in the database table. There is no type checking of query parameters and there is no IntelliSense support either. Language-Integrated Query (LINQ) allows developers to create set-based queries in application code, without having to use a separate query language. You can write LINQ queries to... half the sheet of paper... routine and can be single-line or multi-line. You can pass values from the current scope to a lambda expression. (Microsoft definition) The following example is a lambda expression that increments its argument and returns the value. The example shows the single-line and multi-line lambda expression syntax for a function. Example from Microsoft (http://msdn.microsoft.com/en-us/library/bb531253.aspx) Conclusion: This is a short introduction to Microsoft LINQ especially LINQ to SQL. For further reading, visit the links below to explore the power of LINQ;• http://msdn.microsoft.com/en-us/library/bb385100.aspx• http://msdn.microsoft.com/en-us/ vstudio/bb688085.aspx• http://en.wikipedia.org/wiki/Language_Integrated_Query• http://www.codeproject.com/Articles/24448/LINQ-to-SQL-Samples• http://codesamplez.com/ database/tutorial linq-to-sql-c-sharp
tags