Linq

Language Integrated Query (LINQ) is a Microsoft .NET Framework component that adds native data querying capabilities to .NET languages. Please consider using more detailed tags when appropriate, for example [linq-to-sql], [linq-to-entities] / [entity-framework], or [plinq]

59 votes
10 answers
1.9K views
Join/Where with LINQ and Lambda

I'm having trouble with a query written in LINQ and Lambda. So far, I'm getting a lot of errors here

avatar
Leonardo
0 1 0 9
asked 07 September, 2021
60 votes
19 answers
2K views
How to use LINQ to select object with minimum or maximum property value

I have a Person object with a Nullable DateOfBirth property. Is there a way to use LINQ to query a list of Pe

avatar
Alba
0 1 0 9
asked 07 September, 2021
51 votes
16 answers
2.2K views
LINQ: When to use SingleOrDefault vs. FirstOrDefault() with filtering criteria

Consider the IEnumerable extension methods SingleOrDefault() and FirstOrDefault() MSDN documents that SingleO

avatar
Corrin
0 1 0 9
asked 07 September, 2021
60 votes
22 answers
994 views
Retrieving Property name from lambda expression

Is there a better way to get the Property name when passed in via a lambda expression? Here is what i currentl

avatar
Robyn
0 1 0 9
asked 07 September, 2021
55 votes
16 answers
1.4K views
Is it better to call ToList() or ToArray() in LINQ queries?

I often run into the case where I want to eval a query right where I declare it. This is usually because I nee

avatar
Adolfo
0 1 0 9
asked 07 September, 2021
57 votes
16 answers
2.6K views
Update all objects in a collection using LINQ

Is there a way to do the following using LINQ? foreach (var c in collection) { c.PropertyToSet = value; }

avatar
Robyn
0 1 0 9
asked 07 September, 2021
55 votes
23 answers
1.1K views
LEFT OUTER JOIN in LINQ

How to perform left outer join in C# LINQ to objects without using join-on-equals-into clauses? Is there any w

avatar
Tuan
0 1 0 9
asked 07 September, 2021
58 votes
12 answers
2.9K views
Concat all strings inside a List<string> using LINQ

Is there any easy LINQ expression to concatenate my entire List<string> collection items to a single str

avatar
Alba
0 1 0 9
asked 07 September, 2021
61 votes
10 answers
2.8K views
Use LINQ to get items in one List<>, that are not in another List<>

I would assume there's a simple LINQ query to do this, I'm just not exactly sure how. Given this pi

avatar
Luis
0 1 0 9
asked 07 September, 2021
49 votes
10 answers
1.2K views
Which method performs better: .Any() vs .Count() > 0?

in the System.Linq namespace, we can now extend our IEnumerable's to have the Any() and Count() extension

avatar
Luis
0 1 0 9
asked 07 September, 2021
60 votes
20 answers
3.1K views
Dynamic LINQ OrderBy on IEnumerable<T> / IQueryable<T>

I found an example in the VS2008 Examples for Dynamic LINQ that allows you to use a sql-like string (e.g. Orde

avatar
Patsy
0 1 0 9
asked 07 September, 2021
58 votes
14 answers
536 views
Using LINQ to remove elements from a List<T>

Say that I have LINQ query such as: var authors = from x in authorsList where x.firstname == "B

avatar
Lawanda
0 1 0 9
asked 07 September, 2021
57 votes
10 answers
991 views
IEnumerable vs List - What to Use? How do they work?

I have some doubts over how Enumerators work, and LINQ. Consider these two simple selects: List<Animal>

avatar
Eddie
0 1 0 9
asked 07 September, 2021
58 votes
12 answers
838 views
LINQ Aggregate algorithm explained

This might sound lame, but I have not been able to find a really good explanation of Aggregate. Good means s

avatar
Fabian
0 1 0 9
asked 07 September, 2021
60 votes
22 answers
2.8K views
LINQ equivalent of foreach for IEnumerable<T>

I'd like to do the equivalent of the following in LINQ, but I can't figure out how: IEnumerable<

avatar
Yolando
0 1 0 9
asked 07 September, 2021
60 votes
14 answers
3K views
When to use .First and when to use .FirstOrDefault with LINQ?

I've searched around and haven't really found a clear answer as to when you'd want to use .Firs

avatar
Sena
0 1 0 9
asked 07 September, 2021
53 votes
14 answers
907 views
Group By Multiple Columns

How can I do GroupBy multiple columns in LINQ Something similar to this in SQL: SELECT * FROM <TableName>

avatar
Nereida
0 1 0 9
asked 07 September, 2021
63 votes
23 answers
280 views
LINQ query on a DataTable

I'm trying to perform a LINQ query on a DataTable object and bizarrely I am finding that performing such

avatar
Dorian
0 1 0 9
asked 07 September, 2021
57 votes
10 answers
2K views
Group by in LINQ

Let's suppose if we have a class like: class Person { internal int PersonID; internal string c

avatar
Omar
0 1 0 9
asked 07 September, 2021
62 votes
14 answers
1.3K views
Returning IEnumerable<T> vs. IQueryable<T>

What is the difference between returning IQueryable<T> vs. IEnumerable<T>, when should one be pref

avatar
Leonardo
0 1 0 9
asked 07 September, 2021