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]

58 votes
8 answers
2.1K views
Combining two expressions (Expression<Func<T, bool>>)

I have two expressions of type Expression<Func<T, bool>> and I want to take to OR, AND or NOT of t

avatar
Kisha
0 1 0 9
asked 07 September, 2021
60 votes
8 answers
655 views
LINQ: Not Any vs All Don&apos;t

Often I want to check if a provided value matches one in a list (e.g. when validating): if (!acceptedValues.A

avatar
Don
0 1 0 9
asked 07 September, 2021
60 votes
5 answers
1.6K views
Why does ReSharper tell me "implicitly captured closure"?

I have the following code: public double CalculateDailyProjectPullForceMax(DateTime date, string start = null

avatar
Tana
0 1 0 9
asked 07 September, 2021
56 votes
6 answers
2.1K views
Convert string[] to int[] in one line of code using LINQ

I have an array of integers in string form: var arr = new string[] { "1", "2", "3", "4" }; I need to an arr

avatar
Karolyn
0 1 0 9
asked 07 September, 2021
54 votes
17 answers
1K views
Entity Framework: There is already an open DataReader associated with this Command

I am using Entity Framework and occasionally i will get this error. EntityCommandExecutionException {"There

avatar
Suzan
0 1 0 9
asked 07 September, 2021
60 votes
23 answers
2.8K views
How do I concatenate two arrays in C#?

int[] x = new int [] { 1, 2, 3}; int[] y = new int [] { 4, 5 }; int[] z = // your answer here... Debug.Asser

avatar
Suzan
0 1 0 9
asked 07 September, 2021
52 votes
19 answers
460 views
Using Linq to get the last N elements of a collection?

Given a collection, is there a way to get the last N elements of that collection? If there isn't a metho

avatar
Santiago
0 1 0 9
asked 07 September, 2021
62 votes
9 answers
1.5K views
How to perform .Max() on a property of all objects in a collection and return the object with maximum value

I have a list of objects that have two int properties. The list is the output of another linq query. The

avatar
Dario
0 1 0 9
asked 07 September, 2021
61 votes
16 answers
713 views
How would you do a "not in" query with LINQ?

I have two collections which have property Email in both collections. I need to get a list of the items in the

avatar
Wei
0 1 0 9
asked 07 September, 2021
51 votes
12 answers
1.6K views
Deserializing JSON to .NET object using Newtonsoft (or LINQ to JSON maybe?)

I know there are a few posts about Newtonsoft so hopefully this isn't exactly a repeat...I'm trying

avatar
Clarice
0 1 0 9
asked 07 September, 2021
55 votes
11 answers
1.2K views
Remove duplicates in the list using linq

I have a class Items with properties (Id, Name, Code, Price). The List of Items is populated with duplicated

avatar
Winford
0 1 0 9
asked 07 September, 2021
45 votes
7 answers
646 views
What does LINQ return when the results are empty

I have a question about LINQ query. Normally a query returns a IEnumerable<T> type. If the return is emp

avatar
Thurman
0 1 0 9
asked 07 September, 2021
54 votes
5 answers
822 views
Flatten List in LINQ

I have a LINQ query which returns IEnumerable<List<int>> but i want to return only List<int>

avatar
Dario
0 1 0 9
asked 07 September, 2021
63 votes
17 answers
3K views
Using LINQ to concatenate strings

What is the most efficient way to write the old-school: StringBuilder sb = new StringBuilder(); if (strings.C

avatar
Lashawna
0 1 0 9
asked 07 September, 2021
56 votes
4 answers
1.1K views
Convert Linq Query Result to Dictionary

I want to add some rows to a database using Linq to SQL, but I want to make a "custom check" before adding the

avatar
Kurtis
0 1 0 9
asked 07 September, 2021
52 votes
14 answers
873 views
How to do SQL Like % in Linq?

I have a procedure in SQL that I am trying to turn into Linq: SELECT O.Id, O.Name as Organization FROM Organi

avatar
Venice
0 1 0 9
asked 07 September, 2021
52 votes
11 answers
2.2K views
C# LINQ find duplicates in List

Using LINQ, from a List<int>, how can I retrieve a list that contains entries repeated more than once an

avatar
Cortez
0 1 0 9
asked 07 September, 2021
57 votes
12 answers
1.9K views
What is the difference between IQueryable<T> and IEnumerable<T>?

What is the difference between IQueryable<T> and IEnumerable<T>? See also What's the differe

avatar
Jesenia
0 1 0 9
asked 07 September, 2021
55 votes
6 answers
2K views
LINQ .Any VS .Exists - What&apos;s the difference?

Using LINQ on collections, what is the difference between the following lines of code? if(!coll.Any(i => i

avatar
Virgil
0 1 0 9
asked 07 September, 2021
56 votes
4 answers
2.2K views
LINQ Orderby Descending Query

I'm sure this will be a relatively simple one. I have a LINQ query that I want to order by the most rece

avatar
Sena
0 1 0 9
asked 07 September, 2021