Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [linq]

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

4
votes
2answers
108 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 ...
3
votes
1answer
145 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 ...
1
vote
2answers
67 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 ...
-2
votes
1answer
60 views

Filtering List data using LINQ [closed]

In this code I have declared myPushData, myPushDataFilterd and myPushDataFilterd2 variables ...
11
votes
1answer
106 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 ...
3
votes
5answers
499 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 ...
5
votes
2answers
854 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 ...
0
votes
1answer
78 views

Merging two lists into one by dates [closed]

I have two lists of Slots ...
6
votes
3answers
545 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: ...
-2
votes
1answer
97 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 ...
-2
votes
1answer
232 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: ...
2
votes
3answers
112 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 ...
2
votes
2answers
280 views

Get attribute values with LINQ to XML

I'm pulling the values from the following XML based on the attribute name. ...
3
votes
1answer
61 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 ...
0
votes
1answer
128 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: ...
4
votes
4answers
747 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 ...
2
votes
1answer
90 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 ...
3
votes
3answers
119 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). ...
2
votes
0answers
103 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 ...
4
votes
2answers
143 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 ...
4
votes
1answer
168 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 ...
8
votes
3answers
156 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 ...
4
votes
1answer
85 views

Algorithm for tagging list of substrings from a list of strings

I have a list of utterances(strings)/corpus as the follows, ...
4
votes
3answers
107 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 ...
0
votes
1answer
431 views

adding properties together from list of objects using LINQ

Looking to see if there is a simpler way to achieve this. I would love if I could keep the return as a one-line LINQ expression. I want to grab the total number of ...
1
vote
0answers
88 views

Eager loading using Auto.mapper [closed]

I am using eager loading. My problem that I am having is that when using (Auto.Mapper 4.1.1) Mapper.DynamicMap the method is going back to sql server for each relationship. It's taking about 2 ...
2
votes
0answers
37 views

Correct Way to Retrieve Header Records With Filtered Detail Records [closed]

I wrote this in LinqPad. It works. The whole point was to retrieve header records, and only include some detail records. I'm looking for possible improvements to this, specifically around the ...
2
votes
2answers
780 views

Linq IEnumerable extensions for void functions

I found myself wanting to use Linq to map void methods to an IEnumerable to modify all items. The existing Linq methods require a return variable when mapping, since they are based on ...
2
votes
0answers
81 views

Implementing the IQueryable counterpart method of the IEnumerable method?

I have created this method to simulate SQL's IN operator: ...
5
votes
3answers
1k views

LINQ method that selects an item based on previous one

my requirement is to implement a way to filter a collection of elements based on a value of previous one. For example to only select a number that is larger than the previous one. I don't currently ...
5
votes
2answers
185 views

Porting functional programming code to Linq

I am very new to C# programming, so for practice I thought I would try to port a simple haskell function over to Linq. From learn you a haskell, there is the following implementation of powerset: <...
5
votes
1answer
81 views

Representing relations between devices when presented with only one-to-many mappings

There are devices that communicate between each other. Already existing in the Legacy codebase is a list of one-to-many mappings between the devices. I have written a function in my backend that ...
0
votes
1answer
56 views

Data validation for to check required fields are mapped

Can I break the below foreach and IF statements into LINQ expression. Also, performance wise which will be better. Please suggest. ...
1
vote
0answers
42 views

Querying a database to find notifications to comments

I have a solution what I think is not the best, and I want to make this not so expensive. I'm using MVC 5 + SignalR (hubs) + EF + UnitOfWork + Generic Repos. I have a table ...
6
votes
1answer
62 views
0
votes
1answer
510 views

Entity Framework MVC updating db using a repository method [closed]

I have inherited this code from a legacy project, and it is throwing a New transaction is not allowed because there are other threads running in the session. error. Now I know the problem here is ...
1
vote
1answer
66 views

Search through multiple lists, but have functions that do that in parts

I have an Entity Framework table of Addresses. I'm building a Repository that would allow me to search for an Address by either parts of the Address or the whole address. Here's what I've got so far: ...
0
votes
2answers
1k views

Importing complex XML file into a flat object

I am trying to parse xml file using XDocument, basically, I have to select xml element based on requirement and convert into list model. Below is sample code I am ...
1
vote
4answers
2k views

Chain LINQ expressions for filtering

Example of my method where I am chaining linq expressions based on model values provided: ...
4
votes
2answers
309 views

Accessing fields in LINQ query for customers with overdue balances

Practicing my autodidactism using a free Kindle Unlimited book to get myself acquainted with the basics of C# in hopes of getting enough of a foundation to get into automation and I still feel a ...
0
votes
1answer
100 views

Add data into lists at runtime, from a database

Presentation: I am trying to write classes to store data from a database. The data consists in objects, let's call them "Areas". Each area has a name and possibly 'child' areas: ...
4
votes
2answers
9k views

Creating a list with nested lists

I have made algorithms to create a list with nested lists in order to then show them in a tree view. From what users told me, my view method is fine, but the way I create the final list is probably ...
1
vote
2answers
4k views

Split a list of objects into a list and a grouping, based on criteria

I'd like to know what's the most efficient and correct way to do the following: We're given a list of objects. Here's an exampler object: ...
6
votes
2answers
8k views

Get total count of object's elements and all children objects` elements

I have a table, Taxonomy, with data that looks something like the following: ...
5
votes
2answers
2k views

Efficiency of a linq query on a nested structure

For a survey website I've written this query to show the survey results, with a percentage for each chosen answer: ...
1
vote
1answer
73 views

Aggregating clients and client types

The code I have put together achieves what I want, but I don't know if it is the right way to go about tackling the problem. I am dealing with 2 tables (CLIENT, CLIENTTYPE) each of which I have an ...
7
votes
1answer
1k views

GroupBy(params string[] fields)

Linq to Object GroupBy extension method allows grouping by projection: ...
4
votes
4answers
604 views

Selecting names with two consecutive, same letters

I've a list of names that I'd like to iterate over and extract from it those names that have two letters that are the same right next to each other (i.e. Bill, Terry, Debby, Aaron, etc.). The below ...
9
votes
3answers
494 views

LINQ-ifying Colour Generation from Strings

Recently I was thinking about how Google, Microsoft Outlook on Windows Phone (and now many others) method of giving you a coloured icon with a letter in the centre of it works. Essentially, given ...
-3
votes
2answers
93 views

Classes for plotting data in daily, monthly, and yearly groups

I have the following code, Only difference is way it groups data, Is there any way to make this into one logic by passing group by arguments, So the duplicate code can be removed. ...