LINQ Samples

Are you looking for LINQ Samples? Find LINQ Samples, snippets and examples.



You can make money from this site by posting original and quality articles that comply with Google AdSense policies.. Also, we offer several other reward programs including monthly profit sharing, cash rewards per post, contests & prizes etc to contributing members.

Submit Your Article

Articles

Implement Sql Server Rank and DenseRank Functions in 'LINQ Expressions'

In a class there are 100 students, and in a talent test they got some marks. I want to rank those students. To implement this, SQL Server provides two functions called Rank() and Dense_Rank(). Briefly, Rank() Returns the rank of each row in the result set of partitioned column. Dense_Rank() is same as RANK() function. Only difference is returns rank without gaps. Here i am providing those functions implementation in C# using LINQ expressions.

Filtering data table using LINQ query

LINQ can be used on data tables to filter out those rows from the data table which matches the filter criteria. LINQ query improves performance as compared to traditional Select() method on data table.

Using LINQ to XML

Here I would like to explain how to use LINQ to Query XML and XML Objects. As we know, XML is extensively used because of its popularity. XML provides data in a more accurate, flexible, and adaptable way.

Aggregate Operators In LINQ

In this article we will discuss about the Aggregate Operators in LINQ. The Aggregate Operators in Linq allow us to perform simple math operations over the elements in a sequence. There are mainly six types of Set Operators in Linq.

LINQ example using XML file

This article describes basic LINQ query that getting some data from XML file and bind a gridview.Here there is XML file name employees.xml where each employee have four attribute as FirstName, LastName, Department, Location. Our aim is to select all Department into a dropdownbox and then when we select one department and press Button then all Employee details will appear into a Gridview. I have taken two class file as Employee.cs and EmployeeService.cs and one aspx page

How to Write Inline SQL-Queries in DataContext Class

For a new programmer in Linq writing Complex Linq queries like Joins for multiple tables , using Lambda expressions and preparing dynamic queries is a bit difficult thing.Because he/she is not Used to it.For all those Programmers this article will give some relief and they can write ordinary queries and execute in datacontext to get Object as resultset.This Article will demonstrate how to use these Methods. I will illustrate with snippet of Code Lines.

Linq Getting distinct values from a custom list

Do you want to learn how to get the distinct values from a list of data using LINQ. Here in this article I would be demonstrating one such example where I would be displaying the distinct names of employee from an employee list.

Gridview Column sorting using Expression Tree

Does your project requires you to generate the Lamda expression at run time? Check out my resource. Here I have provided the code snippet to dynamically calculate the Lamda expression based on the grid columns.

Set Operators in Linq

In this article we will discuss about the Set Operators in LINQ. The Set Operators in Linq is some what same as that of SQL Set operators where their primary use is to find the Union, Intersection, Except, Concat and Distinct.


Ordering Operators in Linq

In this article we will discuss about the Ordering Operators in LINQ. Ordering Operators are used whenever we wants to sort the collections in some specific manner which can be ascending, descending or simply reversing the collection.

Partitioning Operators in Linq

In this article we will discuss about the partitioning operators in LINQ. Partitioning operators mean that to get some specific values from a collection. There are mainly four types of Partition Operators are there. 1. Take 2. Skip 3. TakeWhile 4. SkipWhile

How to write Fluent Linq Queries?

This article helps you to understand Linq a little more easily. I have used Fluent expressions to write the LINQ queries.I have also used normal queries to that you can differentiate between the fluent queries and the normal queries.Its easy to write both types of queries, you have to decide in which way you want to write that.

Different Sorting techniques (delegate with anonymous method, lamda)

In this article, I have given a code snippet that can refer while writing your code for sorting a collection of objects based on various criteria. First technique is based on delegate, where anonymous method is used to compare and return data. Rest of the techniques are based on lambda expressions. Different GridView are used to present outputs of separate Sorting.

LINQ: ToLookup() vs ToDictionary()

This is about a new feature in .net called ToLookup() a extension method on IEnumerable objects. Most of us have used Dictionary object which will have a key value pair. But what if you want to have multiple value for a single key? There you need this lookpu, you have use this ToLookup() extension method and make a lookup object which will have key, collection of values on it.

Update the Attribute value using LINQ

Here i would like to show you, how to Query the XML using LINQ and Update the attribute value for one of the Element. Here i am using LINQ to load the XML and Query the XML to get the element based on its attribute value. Getting the child element we will update the value of attribute for one of the child element.

Store procedure in MVC

In this resource you will know how to create store procedure for selecting data in database . Model store procedure is given in this resource .How to Call Store procedure in MVC given in this resource.

Submit Your Article