Questions tagged [linq]

Language INtegrated Query (LINQ) is a Microsoft .NET Framework component that adds native data querying capabilities to .NET languages.

Filter by
Sorted by
Tagged with
7 votes
2 answers
436 views

Iterate only once using LINQ

Funny thing, the following test works: ...
Dmitry Nogin's user avatar
  • 6,123
4 votes
1 answer
358 views

Paginate IEnumerable<T> sequence

I used the following to split sequence into batches: ...
Dmitry Nogin's user avatar
  • 6,123
4 votes
2 answers
173 views

Finding which items have at least one common value with other items

I have the following collection : ...
tigrou's user avatar
  • 421
1 vote
1 answer
162 views

ASP.NET MVC 5, EF 6 filter performance

I'm creating a filter with Linq in an ASP.NET MVC application. I was hoping I could get some tips on performance enhancements, aside from any possible performance enhancements. I have a few questions:...
Train's user avatar
  • 301
8 votes
3 answers
9k views

LINQ Extension methods MinBy and MaxBy

LINQ Extension I present a LINQ method ArgBy that returns the item of a sequence that corresponds to the predicate specified. Two additional methods ...
dfhwze's user avatar
  • 13.9k
4 votes
2 answers
804 views

Reverse Dictionary: Group from child array elements and get its minimum key

Objective I have following array and would like to group by each child and get its smallest Id:- ...
Zephyr's user avatar
  • 225
4 votes
2 answers
483 views

DropDown tree with search

I fetch a bunch of categories for a DropDown tree, and have to implement search in this dropdown. If there is a match in one of the elements, it should also get all ...
Tim Maes's user avatar
  • 153
5 votes
1 answer
311 views

Make utility using LINQ

Make() takes projects with a list of tuples representing project references in the form of (Dependency, Dependent) and returns ...
Dmitry Nogin's user avatar
  • 6,123
7 votes
4 answers
6k views

LINQ for generating all possible permutations

Permutate() is supposed to generate all possible permutations of the source sequence: ...
Dmitry Nogin's user avatar
  • 6,123
3 votes
1 answer
158 views

LINQ for extracting N bottom items (async streams)

source.Bottom(n, x => x) should be the same as well known LINQ source.OrderBy(x => x).Take(n) but is more memory/run-time ...
Dmitry Nogin's user avatar
  • 6,123
9 votes
4 answers
4k views

Filter search results by multiple filters in one operation

I want to filter search results by multiple filters at once. Is it possible to reduce the number of if statements? My code: ...
Mykhailo Mushynskyi's user avatar
1 vote
0 answers
1k views

E-Commerce Mock App in Console

I have completed this E-Commerce Mock App in Console C# which I used object to store the data to apply some C# OOP and LINQ techniques. Since it is just a mock version, features are reduced to the ...
Steve Ngai's user avatar
17 votes
3 answers
2k views

ExactlyOne extension method

I often find in codebases something on the order of if (sprockets.Count() > 0) which is easily replaced with LINQ's ...
Jesse C. Slicer's user avatar
5 votes
2 answers
139 views

PLINQ code analysis in terms of efficiency of cryptographic hashes generation

I have the following code that I wrote in order to find the correct password by generating hashes out of all possible combinations and comparing each of them with the target. I'm trying to make ...
JustArchi's user avatar
7 votes
5 answers
1k views

Grouping into more groups in one iteration

I had a need to group the same dataset in several groups. So instead of repeatedly query the dataset, I made an extension that could do it once. The caveat is, that the result is materialized in ...
user avatar
5 votes
3 answers
995 views

SkipLast of an IEnumerable<T> - Linq Extension

As my answer to this question, I came up with this solution: ...
user avatar
2 votes
1 answer
160 views

Performance issue with empty lists

Here's my updated version of the problem I posted at Calculating time windows for entities, adding in suggested changes as well as a change I did so that the Reflection is 'cached' in a ...
Mark Cilia Vincenti's user avatar
2 votes
1 answer
84 views

Populating dropdown lists, using SQL vs. using expression trees and reflection

I'm working with a large enterprise SQL Server database with dozens of tables that are used mainly as lookups to populate dropdown lists, etc. These tables all follow the convention of having (table)...
Valuator's user avatar
  • 189
3 votes
1 answer
923 views

Non brute force algorithm for Birthday Chocolate

Problem: https://www.hackerrank.com/challenges/the-birthday-bar/problem Lily has a chocolate bar that she wants to share it with Ron for his birthday. Each of the squares has an integer on it. She ...
David's user avatar
  • 131
3 votes
0 answers
41 views

Configure multiple application features by common criteria

My FeatureSerivce provides only basic APIs, so it is good in dealing with single features. Like I can configure only one feauture at a time: ...
t3chb0t's user avatar
  • 44.1k
2 votes
2 answers
51 views

LINQ queries to generate a report on accrued work time on projects

The following code fetches data from a MySql database to generate a simple report on accrued work time on projects. I've been away from Entity Framework for a while and looking at this code you can ...
w4n's user avatar
  • 21
0 votes
2 answers
1k views

Poker Hand evaluation

I want to evaluate Poker Hands an wrote the following Code: https://dotnetfiddle.net/mxMvq9 Anything wrong / to imporve? ...
fubo's user avatar
  • 365
6 votes
5 answers
4k views

Take N elements from List of Lists

I've come with a solution super tricky for a simple requirement. I think I could solve the problem using LinQ, but I'm not seeing it so clearly at all. What's sure, I'm not comfortable with my code. ...
Facundo La Rocca's user avatar
3 votes
2 answers
4k views

Group list into elements with same value

This is my Result class: ...
dafie's user avatar
  • 299
2 votes
1 answer
260 views

Parse through an XDocument efficiently and match values to matching object

Minimum viable test program: ...
yhyrcanus's user avatar
  • 131
0 votes
1 answer
576 views

LINQ or Lambda for two foreach query [closed]

I have a Document Name Table in my SQL database and Files in the Content folder. I have two lists: ListOfFileNamesSavedInTheDB and ...
AliAzra's user avatar
  • 119
4 votes
2 answers
311 views

Making a list of customers who buy the top N items from a supplier

I have a method that works perfectly well and does what it's supposed to, albeit a little slow (30 - 40 seconds). I would like to be able to speed it up or at least make it more efficient, any ideas ...
Lee Morgan's user avatar
3 votes
1 answer
400 views

Logging inside a Linq fluent chain [closed]

I've posted this to Stack Overflow, but someone voted to close as they felt it was opinion based, so I'm bringing it over to Code Review. I have some Linq fluent chains to shape an original ...
mrlucmorin's user avatar
1 vote
2 answers
5k views

Using IQueryable.GroupBy to count related database entities

Given a DbSet<Client> from an Entity Framework 6 DbContext, I need to count the number of related ...
Sinjai's user avatar
  • 227
-2 votes
1 answer
2k views

Filtering List data using LINQ [closed]

In this code I have declared myPushData, myPushDataFilterd and myPushDataFilterd2 variables ...
Arvind's user avatar
  • 107
12 votes
1 answer
5k views

Linq for ObservableCollection

Purpose ObservableCollection<T> is not strictly a WPF class, but its intended purpose seems to be for use in WPF. It's the standard implementation of ...
Peter Taylor's user avatar
  • 24.1k
3 votes
5 answers
1k views

Finding Isogram Word

An isogram (also known as a "nonpattern word") is a word or phrase without a repeating letter, however spaces and hyphens are allowed to appear multiple times. The ...
AKdeBerg's user avatar
  • 195
5 votes
2 answers
892 views

Going from IQueryable<IEnumerable<myObj>> to IEnumerable<myObj>

I have a "GetPersonsPerDepartment()" method returning a IQueryable<IEnumerable<Person>> while I'm trying to get a simple ...
MmM's user avatar
  • 409
1 vote
1 answer
3k views

Merging two lists into one by dates [closed]

I have two lists of Slots ...
garret's user avatar
  • 111
8 votes
4 answers
2k views

Custom implementation of the linq Zip operator for different length lists

Based on my answer I have my implementation of linq Zip operator which operates on different length lists, and loops shortest list. My implementation: ...
BWA's user avatar
  • 251
-2 votes
1 answer
1k views

Method to populate a dictionary from properties

I have a class with some properties. In the class I have a method that is "collecting" all the properties in a specific instance of the class to a dictionary, with the properties name being the ...
Jacce's user avatar
  • 11
-1 votes
1 answer
2k views

Reuse Select Expression in LINQ

I have three methods to get the user details based on attributes: Find user details by id, Find user details by username, Find user details by email Here is the program class: ...
Arasu RRK's user avatar
  • 115
2 votes
3 answers
491 views

Grouping report data by one of two criteria

I have a report with a group by filter. A stored procedure returns all the data and maps it to IEnumerable<EventListRow>. The code should then group the data ...
Stephen Richardson's user avatar
3 votes
2 answers
5k views

Get attribute values with LINQ to XML

I'm pulling the values from the following XML based on the attribute name. ...
inquisitive_one's user avatar
4 votes
1 answer
173 views

Determining if there is data left after fetching a page of data

I just faced a problem where I needed to know if extra data was present in a given collection after a Take operation took place. Specifically, this is related to ...
julealgon's user avatar
  • 224
0 votes
1 answer
706 views

Sorting table using multiple columns [closed]

I want to sort entries in a given list on Entry column in most efficient way. Here is how my entries look: ...
A.Learn's user avatar
  • 53
5 votes
4 answers
821 views

Take a desired string, iterate through objects to see if it exists in a given field and append a number until a unique string is found

I wanted to in the most generic way possible write a method in C# to achieve the following. Take in a string, a set of objects, and a function to access the field of a given object Look at all of the ...
Geesh_SO's user avatar
  • 193
2 votes
1 answer
410 views

Handling related generic type parameters

In answering a question on StackOverflow, it occurred to me that a more generic version of GroupBy for C# that delegated membership in each group to a class could ...
NetMage's user avatar
  • 412
5 votes
4 answers
986 views

Add dash between more than two consecutive numbers and comma between other numbers in array

I have an ordered array of integer values: 10, 11, 12, 13, 15, 16, 19 and I need to write a dash between first and last consecutive values when there are more than two consecutive values (10-13). ...
HelloWorld's user avatar
2 votes
0 answers
263 views

Handler for jQuery DataTable search with filters and pagination

This AjaxCompound is invoked every time when the user types a key for search or click to sort. It contains 1million data 10 distinct rows by compound name. It takes 1.1 minutes and return only 1-5 KB ...
Ujwal Neupane's user avatar
4 votes
2 answers
265 views

EnumerableHelpers: a partial implementation of LINQ for .NET Framework 2.0

Here is a static class with some helper methods for some common LINQ operations on enumerables, built against .NET Framework 2.0. This class is part of the xofz.Core98 library. Edit: a full review ...
xofz's user avatar
  • 478
4 votes
1 answer
701 views

Find a list of Windows Services by given criteria

My goal is to implement a method, which finds a list of Windows Services that match given set of criteria: SearchString: A search string ...
Alexey's user avatar
  • 145
8 votes
3 answers
184 views

Build clusters from connections (virus propagation)

The scenario is the following: There is a list of persons and places where those persons visit. Each person is connected to a single or multiple places. See the picture below, where O[i] represents ...
L_J's user avatar
  • 263
5 votes
1 answer
116 views

Algorithm for tagging list of substrings from a list of strings

I have a list of utterances(strings)/corpus as the follows, ...
Kunal Mukherjee's user avatar
4 votes
3 answers
118 views

List mapping of large data set from file

I have a list of items 116 thousand and my mapping function is taking quite some time to process. I am using the file helpers library to write the CSV to disk but its the for each that is taking ...
David B's user avatar
  • 143

1
2
3 4 5
13