Tag: linq

57 votes
4 answers
1.3K views
Populate XDocument from String

I'm working on a little something and I am trying to figure out whether I can load an XDocument from a st

avatar
Solomon
0 1 0 9
asked 07 September, 2021
55 votes
7 answers
1.1K views
XDocument or XmlDocument

I am now learning XmlDocument but I've just ran into XDocument and when I try to search the difference or

avatar
Hildegard
0 1 0 9
asked 07 September, 2021
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
653 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
458 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
62 votes
23 answers
2.2K views
Entity Framework. Delete all rows in table

How can I quickly remove all rows in the table using Entity Framework? I am currently using: var rows = from o

avatar
Boyd
0 1 0 9
asked 07 September, 2021
61 votes
16 answers
711 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
644 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
820 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
872 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