Click here to Skip to main content
15,881,812 members
Everything / LINQ

LINQ

LINQ

Great Reads

by Nish Nishant
An ExifReader class in C# that supports custom formatting and extraction. StyleCop compliant code, with demos for WPF and Windows Forms.
by Daniel Vaughan
Create best-in-breed cross-platform MVVM apps using Calcium for Xamarin.Forms.
by Roman Kiss
This article describes a design, implementation and tooling of model driven WorkflowServices logically centralized in the Repository and physically decentralized for their runtime projecting.
by Max Paulousky
This article presents the techniques and caveats of building Silverlight applications that can be notified about database state changes via polling duplex. WSHttp binding and CLR triggers are used to implement the solution as well.

Latest Articles

by Dario Picca
Save Key and Value in JSONformat using C# and LINQ
by Tragdor
A quick lesson in LINQ and dynamic Lambda statements
by Dev Leader
This article is follow up content to previous articles I've written about iterators and collections, but the benchmark results were NOT what I expected!
by Kenji Elzerman
Let's take a look at the very fundamentals of LINQ and how to use it.

All Articles

Sort by Score

LINQ 

21 Jan 2013 by Srinivasu Pemma
This tip provides an easy way of dealing with different types of data sources for LINQ Group By taken from my blog http://www.srinetinfo.com/2012/12/linq-group-by.html
7 Oct 2014 by Milad Ashrafi
We need this script for database based ASP.NET websites for using HTML content in post pages.
3 Sep 2014 by debashishPaul
How to convert LINQ query to DataTable
26 Oct 2010 by Matt T Heffron
Since SortedSet has a constructor that takes an IEnumerable parameter, the ToSortedSet extension method can be greatly simplified:public static SortedSet ToSortedSet(this IEnumerable t){ return new SortedSet(t);}
8 Apr 2011 by Henry Minute
Or, there's always Scott Guthrie's LINQ To SQL Debug Visualizer[^].[Edit]While I'm posting links there is a nice utility that can output the generated SQL to the Debug Window in VS written by Kris Vandermotten.You can get it here[^].To use it: MyDataContext db = new...
25 Jan 2012 by Sion Cohen
An elegant programmatic solution for having multiple indexers in C#
18 Jul 2013 by Mannava Siva Aditya
Uploading multiple files and creating a Zip file in ASP.NET with C#.
31 Oct 2013 by Debopam Pal
How to bring data from Entity model to Excel file using LINQ.
14 Apr 2014 by Maninder Singh Puhi
Appropriate query to fetch required no of results from DB instead of getting all at on time for binding controls like Gridview, listview etc
28 Sep 2014 by Vahid_N
It's easy to forget not disposing object contexts, which leads to memory leaks and also leaves too many related connection objects not disposed as well.
19 Jan 2011 by Pranay Rana
Linq Joins with SelectMany
27 Apr 2012 by Tony Dubey
This code demonstrate pros and cons of PLINQ as compared to LINQ
29 May 2014 by Randy Kroeger
Created a POC that dynamically builds a predicate using Expression and Reflection.
29 Nov 2015 by Michael Bogaerts
What brings the 15.2 release for XAF (win) developers
21 Apr 2010 by Mr Orange
Introduction...
17 May 2010 by Rama Krishna Vavilala
I will just make it a little more compact by omitting the Contains method:public static string GetValue(this XElement root, string name, string defaultValue) { return (string)root.Elements(name).FirstOrDefault() ?? defaultValue; }The explicit operators for XElement...
7 Mar 2012 by Sunil_Sebastian
Duplicate Notifier for a List using ObservableCollection.
10 Jan 2015 by John L. Vidal
Know how an event in your app is performing by using Reactive Extensions
29 Apr 2015 by HUONG Minh-Luong
How to use PresentationMapper to generate presentation objects
12 Dec 2015 by aboubkr90
A way around "The LINQ expression node type 'Invoke' is not supported in LINQ to Entities"
8 Jun 2010 by basementman
Or, assuming your table has an index, you could do this "old-school" as:select MAX(rows) from sysindexes where id = Object_ID('{tablename}')
3 Dec 2010 by -james
Iterate through the results and extract using system.reflection
20 Oct 2011 by jim lahey
I prefer to use ToTraceString() on the ObjectQuery:http://msdn.microsoft.com/en-us/library/system.data.objects.objectquery.totracestring.aspx[^]It's less intrusive as I don't have to instantiate and dispose the StreamWriter and I have more control over where and how I log the resultant...
28 Feb 2013 by Dav Zen
Simple and easy to use jQuery matrix 2D.
5 May 2013 by mohammad amiri
Paging DataGridView using LINQ in C#.
19 Aug 2014 by Alberto Nuti
How to serialize an object without having to manually instruct the DataContractSerializer class.
14 Feb 2015 by DerStauner
With this library it is possible to query datatables with SQL commands.
26 Aug 2018 by Toby Steed
Walk before you can run
25 Dec 2021 by scott_liu
Entity Framework Core client evaluation was disabled by default since version 3.0 because of performance.
17 Jan 2011 by Michael Agroskin
Many LINQ functions have a hidden parameter useful to generate or analyze sequential indices
29 Jun 2011 by Erich Ledesma
I rather like IEnumerable than IList, parameters should be as general as posible. I think it's really getting very fun up here. Here's my choice, just for strings.public static string Join(this IEnumerable parts, string separator){ if (! parts.Any()) return...
18 Jan 2012 by Namlak
string blah = string.Join(",", cities.Select(c=> c.Name));
27 Feb 2012 by Rishikesh_Singh
Filtering records from List similar to Sql IN Operator using LINQ
16 Mar 2012 by Carlos Conceição
This article how you can use TextToCalcExpression to generate Linq Expressions in runtime
7 Sep 2010 by John Adams
Magnus, I really like the idea! I believe your original idea (posted @ http://www.codeproject.com/KB/linq/LinqToTree.aspx) is even better for the general case - probably better than the solution in the article - it does feel more generic while still being very easy to use.I'm sure you may...
26 Jun 2011 by JP_Rocks
A tip to concatenate a set of strings using comma/pipe
17 Jul 2011 by Philippe Mori
LINQPad is an interesting tool to try queries.LINQPad[^]Perfect tool to try out some alternatives for complex queries. As we can see generated queries and elapsed time, it help a lot to help having fast queries for complex requests.
18 Jul 2011 by AspDotNetDev
If you are the type that likes to debug production code, you can use SQL Profiler to find queries generated by your LINQ statements. This is a technique I recently used because it was so simple and did not require me to recompile anything.Note that StefanHam already posted this alternate...
2 Oct 2011 by Vishnu Kesaraju
Using LINQ to XML to convert datatables to formatted XML.
8 Nov 2011 by Delashmate
Deep Look in the basics of LINQ
27 Aug 2013 by Måns Tånneryd
This tip shows how to significantly speed up inserts of large amounts of data using the entity framework.
14 May 2012 by taha bahraminezhad Jooneghani
Problem around .first() method in EF and a good solution
18 May 2012 by PIEBALDconsult
This is an alternative for "The Elegant Art of Programming"
31 Jul 2012 by HemendraSingh88
Hi, here we will see how to query a DataSet with LINQ(Language Integrated Query).
8 Sep 2012 by suhas.shiv
Custom CheckBoxList in ASP.NET MVC3
3 Nov 2012 by Sarvesh Kushwaha
Export Excel to SQL database table (Sample Code)
28 Mar 2013 by dgDavidGreene
Helper utility replaces magic string property names.
10 Mar 2013 by xibao
Generate class definition for Web API Service Models.
28 May 2013 by David_Wimbley
How to make a comma separated string using Linq
26 Aug 2013 by Måns Tånneryd
This tip shows how to speed up inserts using POCO objects and the entity framework version 5.
23 Feb 2014 by puja11191
This tip shows how can we generate and save XML files
12 Apr 2014 by Robert Lindblom
Removing entity if it exists
17 Feb 2015 by Christ Akkermans
Code for verifying the resources used by DisplayAttribute in order to catch any missing resource strings
15 Jul 2010 by Paul Brower
This tip will allow you to return the value from column X, where column Y matches your filter
24 Jan 2011 by karenpayne
Returns all checked Checkbox controls in a Windows Form container
29 Jun 2011 by Mohammad A Rahman
The idea was good, but I think we could probably do something like below:public static string UsingStringJoin(IEnumerable sList, string separator){ return sList.Any() ? string.Join(separator, sList.ToArray()) : string.Empty;}public static string...
30 Jun 2011 by George Swan
You can use the Aggregate method with a StringBuilder. I've modified Eric's alternative in order to save a bit of code. Only one return statement is needed as an empty StringBuilder returns an empty string.public static string Join(this IEnumerable parts, string separator) { ...
21 Aug 2011 by murtaza dhari
A generic dropdown control using LINQ to SQL and Entities using Reflection
29 Aug 2011 by Itai Basel
Finally found a solution to the annoying LINQ to SQL dbml error: CS0029 : Cannot implicitly convert type 'int' to 'System.Data.Linq.Link'.
13 Nov 2011 by Pranay Rana
DataLoadOptions and How to use in Compiled Linq query
23 Feb 2012 by RupertC
If the order of your columns is different in the LINQ to SQL class from that in the database, then you also need to add a column mapping to the bulk copier. Otherwise you get mysterious errors in some of the loaded columns!In my simple fix, I assume that the names match even if the order may...
27 Jul 2012 by Wendelius
This is an alternative for "Cumulating values with LINQ"
4 Oct 2012 by ravichaitanya.m
The code shown here allows a user to get all public tweets of her /his liking without logging into Twitter and search for tweets with keywords. It also allows the user to search for his/her friends who are tagged in his/her albums.
15 Oct 2012 by Eric Shandil
How to get dictinct records from a datatable in .NET.
5 Dec 2012 by moosa pourghafari
Get LINQ GetCommand parameters.
3 Sep 2013 by karenpayne
Using newer conventions of coding in VS2010 and higher
17 Apr 2014 by Matt T Heffron
This is an alternative for "Subset - Sum Problem with Integer Arrays "
18 Apr 2015 by Nithila Shanmugananthan
Re-usability of view in MVC
12 Nov 2015 by Eduardo Yost
Creating a Web User Control containing an AutoCompleteExtender for data through WCF (JSON) allowing to store the entity selected through EntityFramework. Entity object serialization from the server to the client and the client to the server.
26 Feb 2010 by MarkLTX
When using LINQ to SQL, it can be very useful to see the SQL commands that are generated by your LINQ expressions. Sometimes the results are surprising and you might be able to improve performance by tweaking the LINQ.All you have to do is set the Log property of the DataContext object. ...
18 Feb 2018 by Max Vagner
Converting mainframe EBCDIC to ASCII format
18 Jul 2012 by Yves Vaillancourt
Adding an extension method to LINQ to flatten any hierarchical collection
28 Sep 2014 by Bhushan Mulmule
This is terribly unorganized document with mix of MVC, Entity Framework, LINQ, HTML 5 and JQuery how tos...
9 Feb 2016 by João Matos Silva
FlatMapper is a library to import and export data from and to plain text files
25 Jan 2012 by Måns Tånneryd
How to use bulk insert with your LINQ-to-SQL datacontext
4 Aug 2017 by Sharp Ninja
Threading can be a daunting topic. This library takes much of the worry (and mistakes) out of multi-threaded application programming.
11 Jan 2021 by Uladzislau Baryshchyk
Basics of the embedded LINQ language
13 Jul 2015 by Yuriy Anisimov
Expressmapper - lightweight, lighting fast and easy to use .NET mapper
26 Jan 2011 by dan!sh
A simple way to edit a list or collection which is iterated in a foreach loop
29 Apr 2014 by Ashley Davis
The technique presented here is a simple method of resampling and aggregating time series.
5 Oct 2015 by Wendelius
This tip shows one way to query hierarchical data from a DataTable by using an AsTree() method.
10 Sep 2014 by DiponRoy
Let's make a lambda expression from a property name of a particular entity, and use it for OrderBy shorting
22 Apr 2014 by Member 3531622
Get rid of trivial mapping between objects like mapping between obj1.City and obj2.Town or between properties with the same name
26 Apr 2016 by _Noctis_
How to avoid some hardcoded paths with the uses of Environment.UserName
25 Jan 2016 by Gunaprasad Shetty
The tip provides the code snippet for inserting a huge XML file with details such as node level, node value, node desc and node child, etc.The snippet provides the solution for recursive reading of node and provides the value of XML nodes along with its value.
28 Mar 2010 by The Manoj Kumar
Did you ever face a situation where you want to read a delimited file (CSV or any similar format) and want to filter the records on the basis of some conditions (by checking some values against columns).For example, let's assume that Data.txt file contains the following...
1 Oct 2015 by VijayRana
Some useful MVC Attributes (Bind Attribute, HandleError Attribute, HiddenInput Attribute, Remote Attribute)
21 May 2012 by Juan Pablo G.C.
This is an alternative for "The Elegant Art of Programming"
28 Dec 2014 by Pritam Deshmukh
This tip elaborates few useful tricks and shortcuts of VS 2013 mainly for professional edition (You can find them with Ultimate version too).
27 Jun 2012 by Brady Kelly
A quick and easy way to ensure that your Code First DB Initializer is always run when your app starts, not just on the first data access operation
5 Aug 2013 by Physlcu$
A custom ComboBox that supports live filtering of items by Substring-Search or any other Lamda-Expression
8 Oct 2013 by Thomas Corey
Dynamically sort query results using LINQ expressions and reflection.
5 Mar 2013 by Dan Avidar
Lambda expressions short tutorial
14 May 2013 by vijay__p
How to perform CRUD operations using generic repository with EF pattern with and dependency injection.
6 May 2014 by Fitim Skenderi
Build where clause dynamically in Linq
4 Nov 2013 by Jaume González
How to convert any datareader into generic list.