Click here to Skip to main content
15,890,512 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 Title

LINQ 

4 Jan 2011 by Pranay Rana
(Linq and Nullable Values) OR (SQL ISNULL with LINQ)
22 May 2010 by #realJSOP
Don't reinvent the wheel - use the one that's already on the cart.
6 Apr 2010 by TheGreatAndPowerfulOz
The following is far easier to understand and use than the Outlaw's tip (IMHO).text = Regex.Replace(text, "screen_fadetimeout=\"[^\"\']+\"", "screen_fatetimeout="99");It has the following advantages:1. It is one line of code2. It is easier to read3. It is faster (note: XmlElement...
31 May 2016 by Yaseer Mumtaz
.NET interview questions and answers with real world examples and code snippets
29 Nov 2015 by Michael Bogaerts
What brings the 15.2 release for XAF (win) developers
7 Jun 2010 by Lee Humphries
LINQ translates .count() to a SQL query that uses COUNT(*), but on large tables even count(*) can be too slow. Here's another way
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}')
12 Jan 2016 by shijo joseph
An ADO.NET Layer for SQL Server and Oracle which makes it easier for interfacing with database
17 Jul 2014 by Marlon Hizole
8 Mar 2021 by Basem AlShabani
How to solve recurring problems using LINQ
6 Jul 2013 by sumit_kapadia
AutoComplete Texbox with comma separated insertions
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.
19 Aug 2014 by Alberto Nuti
How to serialize an object without having to manually instruct the DataContractSerializer class.
14 Jan 2013 by Kundan Singh Chouhan
Simplest, best and most robust architecture.
28 Sep 2014 by Bhushan Mulmule
This is terribly unorganized document with mix of MVC, Entity Framework, LINQ, HTML 5 and JQuery how tos...
5 Jun 2022 by Ramesh Bevara
An overview of a helper class to build dynamic order by clause in LINQ query in C#
6 May 2014 by Fitim Skenderi
Build where clause dynamically in Linq
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
17 May 2018 by Clifford Nelson
This tip provides examples of how to use the different arguments of the Linq GroupBy extension method.
15 Oct 2012 by Houssem Dellai
Developing a Windows Phone app step by step
22 Mar 2015 by Mathi Mani
In this tip, we will see how to perform case sensitive comparison of datatables using LINQ
22 Dec 2012 by Thomas Daniels
In this tip, I tell you how to cast an IEnumerable to an IEnumerable(T)
6 Jul 2018 by Daniel Ziegelmiller
How to track changes in the ObservableCollection displayed in a WPF DataGrid
8 Sep 2012 by suhas.shiv
Custom CheckBoxList in ASP.NET MVC3
5 Aug 2013 by Physlcu$
A custom ComboBox that supports live filtering of items by Substring-Search or any other Lamda-Expression
5 Apr 2010 by Rami Shareef
Sometimes you need the Linq query result as datatable (I need it today)Use this: public DataTable ToDataTable(System.Data.Linq.DataContext ctx, object query) { if (query == null) { throw new ArgumentNullException("query"); ...
20 Apr 2011 by jonx
Very good stuff. Learned me a lot about how to access to the physical structure of the query.There is also a CopyToDataTable : http://msdn.microsoft.com/en-us/library/bb386921.aspx[^]And for the record here is a C# version:protected DataTable EntityToDatatable(IQueryable Result,...
17 Apr 2012 by Naufel Basheer
Convert complex XML to an object using LINQ
24 Jan 2012 by Mikhail-T
A short one-line way to convert Array or List of any data into custom string via LINQ
18 Jan 2012 by wgross
I would just use:string.Join(",", cities.Select(c=>c.Name))Since Version 4 of the Framework there is an overloaded versions of string.Join for IEnumerable too. It uses a StringBuilder internally and doesn't insert a seperator after the last element as well.I could't find the Join method...
18 Jan 2012 by Namlak
string blah = string.Join(",", cities.Select(c=> c.Name));
24 Jan 2012 by Richard Deeming
If you're stuck with .NET 3.5, you can use the Aggregate extension method[^]:string cities_string = cities.Aggregate(new StringBuilder(), (sb, c) =>{ if (0 != sb.Length) sb.Append(", "); sb.Append(c.Name); return sb;}, sb => sb.ToString());
29 Mar 2010 by The Manoj Kumar
Did you ever face a situation where you want to calculate total number of occurrences of a value in a List object?What approach did you used for it?Did you ever try LINQ for the same? Yes, you can use it. Just look at the example below:class Program{ static void Main() ...
6 Feb 2011 by SuhasHaridas
Create Linq to SQL connection with select, insert, delete, update
16 Mar 2012 by Carlos Conceição
This article how you can use TextToCalcExpression to generate Linq Expressions in runtime
29 Apr 2015 by HUONG Minh-Luong
How to use PresentationMapper to generate presentation objects
20 Jan 2016 by Indresh_Prajapati
This tip will help beginners to implement CRUD operations in ASP.NET MVC 4 with scripting language as KnockOut and Database as MS SQL 2008R2.
26 Jul 2012 by Wendelius
This tip describes few examples how ro cumulate values using an extension method with LINQ
27 Jul 2012 by Matt T Heffron
This is an alternative for "Cumulating values with LINQ"
27 Jul 2012 by Wendelius
This is an alternative for "Cumulating values with LINQ"
2 Oct 2011 by Vishnu Kesaraju
Using LINQ to XML to convert datatables to formatted XML.
13 Nov 2011 by Pranay Rana
DataLoadOptions and How to use in Compiled Linq query
4 Nov 2013 by Jaume González
How to convert any datareader into generic list.
6 Feb 2019 by Maciej Los
C# helper class to convert date into words
5 Mar 2010 by karenpayne
This code permits a developer to determine if a radio button is selected in a container such as a panel or GroupBox using syntax similar to TryParse.Requires Requires Framework 3.5 or higherExamplePrivate Sub Button1_Click() Handles Button1.Click Dim SelectedButton As New...
7 Mar 2012 by Sunil_Sebastian
Duplicate Notifier for a List using ObservableCollection.
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
8 Oct 2013 by Thomas Corey
Dynamically sort query results using LINQ expressions and reflection.
13 Sep 2013 by oryan
Dynamically build Linq2Sql classes based off SQL table
29 May 2014 by Randy Kroeger
Created a POC that dynamically builds a predicate using Expression and Reflection.
23 Mar 2012 by Elvis Begluk
Dynamically generate LINQ query with a custom property.
23 Jun 2014 by ravgill66
Use LINQ to XML to split an XML file into a number of smaller files
18 Feb 2018 by Max Vagner
Converting mainframe EBCDIC to ASCII format
26 Jan 2011 by dan!sh
A simple way to edit a list or collection which is iterated in a foreach loop
12 Apr 2014 by Robert Lindblom
Removing entity if it exists
13 Sep 2012 by Sarvesh Kushwaha
Binding Gridview (or any other data control) with effective paging using LINQ
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
31 Oct 2013 by Debopam Pal
How to bring data from Entity model to Excel file using LINQ.
3 Oct 2018 by Alen Toma
EntityWorker.Core - an alternative to entity Framework
3 Nov 2012 by Sarvesh Kushwaha
Export Excel to SQL database table (Sample Code)
13 Jul 2015 by Yuriy Anisimov
Expressmapper - lightweight, lighting fast and easy to use .NET mapper
24 Oct 2011 by Pranay Rana
Extended ORM generated class
27 Feb 2012 by Rishikesh_Singh
Filtering records from List similar to Sql IN Operator using LINQ
27 Feb 2012 by Greg Sipes
An alternate solution.
22 Oct 2012 by Rajesh Kariyavula
Find the Odds Out in A Generic List
19 Oct 2016 by Midi_Mick
Use LINQ to get the members of a collection that match the members of another collection
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.
25 Dec 2021 by scott_liu
Entity Framework Core client evaluation was disabled by default since version 3.0 because of performance.
9 Feb 2016 by João Matos Silva
FlatMapper is a library to import and export data from and to plain text files
18 Jul 2012 by Yves Vaillancourt
Adding an extension method to LINQ to flatten any hierarchical collection
18 Oct 2011 by CodingLover
How to format unformatted XML string easily with LINQ.
7 Jun 2011 by User-Rock
LINQ to SQL
2 Sep 2014 by Andre van Dun
Generate game list based on list of players in C#
16 May 2016 by Md._Mehedi_Hasan
This tip will help you to generate .xml file in AngularJs and ASP.NET MVC5 using XElement of C#.
17 Jan 2011 by Michael Agroskin
Many LINQ functions have a hidden parameter useful to generate or analyze sequential indices
21 Aug 2011 by murtaza dhari
A generic dropdown control using LINQ to SQL and Entities using Reflection
15 Jul 2010 by Paul Brower
This tip will allow you to return the value from column X, where column Y matches your filter
14 May 2013 by vijay__p
How to perform CRUD operations using generic repository with EF pattern with and dependency injection.
8 Nov 2011 by Delashmate
Deep Look in the basics of LINQ
15 Oct 2021 by BillWoodruff
Create collections of #n sized elements from arrays, lists, and string
5 Dec 2012 by moosa pourghafari
Get LINQ GetCommand parameters.
20 Nov 2011 by Massimiliano Peluso "WeDev Limited"
Get Nested Property value using reflection and Linq.Expression
8 Apr 2011 by cechode
Saw this a while back; it's simpler (dirty and wrong but... ):public static T Get(Func getDelegate, bool DefaultTOnNull = false, T defaultVal = null) where T : class{ T result = null; try { result = getDelegate(); } catch...
24 Jan 2011 by karenpayne
Returns all checked Checkbox controls in a Windows Form container
11 Dec 2012 by Gregory Gadow
With LINQ, you can retrieve an enumeration's metadata, such as its minimum and maximum values and whether it contains a given value.
7 Feb 2010 by Arun Jacob
Sometimes we want to compare the property names like,if (e.PropertyName == "FirstName"){//Do Something}But this is not type safe. If we change the property name then this won’t work as expected and also it won’t throw compile time error. For getting property name for Type safe...
10 Feb 2010 by Dev_2580
For the last couple of days, working on my project for my studies I have struggled with this annoying issue regarding LINQ to SQL classes.When we update an entity within a DataContext, we can simple use something likecontext.Entity.Attach(updatedEntityInstance)The proplem is that...
7 Oct 2014 by Milad Ashrafi
We need this script for database based ASP.NET websites for using HTML content in post pages.
3 Feb 2011 by debolina.d
Limit the number of records that can be fetched from database based on its count like using the LIMIT clause in MySql
3 Sep 2014 by debashishPaul
How to convert LINQ query to DataTable
3 Dec 2010 by -james
Iterate through the results and extract using system.reflection
20 May 2014 by Ed Nutting
How to fix LocalDB / SQL Server: "Cannot open database "XYZ" requested by the login. The login failed. Login failed for user ABC"
12 Dec 2014 by karimbaig5
This tip provides an idea about how to insert a record into a table having no primary key using LINQ to SQL.
24 Oct 2011 by Pranay Rana
Log your LINQ query
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...
23 Jan 2018 by The Myth
How to return Json in VB.NET in multiple ways
10 Dec 2009 by EuGenius_Krivbass
Today I was trying to save list of entities those were generated by DBMLThis code shows how you can store your list in XML string and put it in ViewState, after that you get your list back.Using the CodeYou can use this code as you need.Here is class Serializatorpublic class...