Language Integrated Query (LINQ, pronounced "link") is a Microsoft .NET Framework component that adds native data querying capabilities to .NET languages.
Microsoft LINQ defines a set of proprietary query operators that can be used to query, project and filter data in arrays, enumerable classes, XML (XLINQ), relational database, and third party data sources. While it allows any data source to be queried, it requires that the data be encapsulated as objects. So, if the data source does not natively store data as objects, the data must be mapped to the object domain. Queries written using the query operators are executed either by the LINQ query processing engine or, via an extension mechanism, handed over to LINQ providers which either implement a separate query processing engine or translate to a different format to be executed on a separate data store (such as on a database server as SQL queries (DLINQ)). The results of a query are returned as a collection of in-memory objects that can be enumerated using a standard iterator function such as C#'s foreach.
Note: Why and wher LINQ is used extensively?
LINQ is the common way to handle the datasources. I would like to give you a simple example, when we develop products which can interact with different datasources like oracle, sql server, mysql or xml files we use different syntax to handle the data. For this we used to maintain different sql statements/sql classes for different datasources. If we use LINQ we can use the same classfiles, statements to interact with different datasources, by just changing the connection string in the web.config file.
LINQ is a common platform for interacting with the datasources. We can perform all operations using LINQ like union, distinct, joins, selecting columns from different tables etc.
Simple Steps involved in creating a LINQ to SQL Class:
step1: Right click on the solution-> Add New Item--->LINQ to SQl Class
step2: This will create a LINQ to SQL class (.dbml file extension).
step3: Now just drag and drop tables, SP, Functions, Views from the server explorer into this .dbml file.
step4: This will create a class for each table with properties, function for the table to interact with the actual database.
step5: We can used these in our code by instantiating the datacontext object.
Like: datacontextobj. TblCustomers or
datacontextobj. FunctionName(Pa rameters) etc...
Example:
-------------
LINQ Data Source :
In the above example USER_GROUPS is the table name, ContextTypeName is the name of the datacontext we have added to our project.
Note:
InsertAllOnSubb mit , DeleteAllOnSubm it This allows multiple delete/inserts at a time increasing the performance db interaction.
Example2:
Syntax for LINQ:
Thanks
Bharath Reddy VasiReddy
Microsoft LINQ defines a set of proprietary query operators that can be used to query, project and filter data in arrays, enumerable classes, XML (XLINQ), relational database, and third party data sources. While it allows any data source to be queried, it requires that the data be encapsulated as objects. So, if the data source does not natively store data as objects, the data must be mapped to the object domain. Queries written using the query operators are executed either by the LINQ query processing engine or, via an extension mechanism, handed over to LINQ providers which either implement a separate query processing engine or translate to a different format to be executed on a separate data store (such as on a database server as SQL queries (DLINQ)). The results of a query are returned as a collection of in-memory objects that can be enumerated using a standard iterator function such as C#'s foreach.
Note: Why and wher LINQ is used extensively?
LINQ is the common way to handle the datasources. I would like to give you a simple example, when we develop products which can interact with different datasources like oracle, sql server, mysql or xml files we use different syntax to handle the data. For this we used to maintain different sql statements/sql classes for different datasources. If we use LINQ we can use the same classfiles, statements to interact with different datasources, by just changing the connection string in the web.config file.
LINQ is a common platform for interacting with the datasources. We can perform all operations using LINQ like union, distinct, joins, selecting columns from different tables etc.
Simple Steps involved in creating a LINQ to SQL Class:
step1: Right click on the solution-> Add New Item--->LINQ to SQl Class
step2: This will create a LINQ to SQL class (.dbml file extension).
step3: Now just drag and drop tables, SP, Functions, Views from the server explorer into this .dbml file.
step4: This will create a class for each table with properties, function for the table to interact with the actual database.
step5: We can used these in our code by instantiating the datacontext object.
Like: datacontextobj. TblCustomers or
datacontextobj. FunctionName(Pa rameters) etc...
Example:
-------------
LINQ Data Source :
Code:
<asp:LinqDataSource ID="LinqDSUserGroups" runat="server" ContextTypeName="Namespace.OurDataContexNamet"
TableName="USER_GROUPS" EnableUpdate="True" OrderBy="Name" Where=" ApplicationId = @ApplicationId ">
<WhereParameters>
<asp:ControlParameter ControlID="hdnApplicationID" Name="ApplicationId" PropertyName="Value"
DbType="Guid" ConvertEmptyStringToNull="False" />
</WhereParameters>
</asp:LinqDataSource>
Note:
InsertAllOnSubb mit , DeleteAllOnSubm it This allows multiple delete/inserts at a time increasing the performance db interaction.
Example2:
Syntax for LINQ:
Code:
( from aliasName in datacontext_objext.TableName where aliasName.ColumnName = 'xyz' Select aliasName.ColumnName).OrderBy(aliasName.OrderbyColumnName).ToList();
Bharath Reddy VasiReddy