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
5 votes
1 answer
13k views

Simplifying a LINQ expression that finds the largest date smaller than another date

I have a LINQ 2 SQL query that needs to run a subquery in the where clause. The subquery just returns the largest date (from a date column) that is less than or equal to another date (an input to the ...
Dan's user avatar
  • 575
5 votes
2 answers
138 views

Asynchronously loading a point in chart on drag

I have some code that asynchronously loads some point in a chart when a users drag it: ...
user75534's user avatar
5 votes
1 answer
700 views

Optimize code block for LINQ and non LINQ

I have 2 code block to do same a work and have same target create some thing, but I don't know which block is the best (I mean LINQ or non-LINQ)? First of all, can anyone tell me how to optimize on ...
user51150's user avatar
5 votes
2 answers
3k views

Convert looping statement to linq mode

I have a model object class like this ...
None's user avatar
  • 377
5 votes
2 answers
456 views

Retrieving data based upon text entered in a textbox

I have two text boxes and one combobox. I am retrieving the data based upon the text entered into the text boxes and combobox selection, by using the following method: ...
Glory Raj's user avatar
  • 189
5 votes
1 answer
117 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
5 votes
3 answers
3k views

HackerRank woman codesprint: minimum cost

Lauren has a chart of projected prices for a house over the next n years, where the price of the house in the i-th year is <...
Jianmin Chen's user avatar
  • 2,396
5 votes
2 answers
12k views

Find a serial port device through WMI (windows management instrumentation)

The idea here is to be able to find a USB serial port device connected during runtime, thus not knowing its port number, and use it in the application to retrieve information from the device. ...
Oscar Guillamon's user avatar
5 votes
1 answer
397 views

Grouping and summing values for food takeout

I have 4 properties which I calculate using LINQ: ...
DeMama's user avatar
  • 151
5 votes
1 answer
131 views

EF query for calculating monthly trends

My application has a fairly important query that is used in a lot of places. Unfortunately it takes about 14 seconds to run, so I'd like to find a way of possibly improving it. The application ...
mfanto's user avatar
  • 151
5 votes
1 answer
22k views

Convert hex string to byte array

The goal is to convert a hex string to a byte array with the following requirements: \$O(1)\$ additional space apart from input and output. \$O(n)\$ runtime This mostly just prohibits creating a new ...
Voo's user avatar
  • 525
5 votes
1 answer
735 views

Producing queries based on user interface selection

I have written a module in my application that makes extensive use of dynamic LINQ to produce Linq/SQL queries based on user interface selection. Currently, the Linq-SQL translation is resulting in ...
Patrick McCurley's user avatar
5 votes
2 answers
2k views

Reorder objects based on provided enumerable order

This code feels like it goes through too many conversions to accomplish my goal: based on an IEnumerable of ids get those objects from a data store and set their ...
ahsteele's user avatar
  • 151
5 votes
1 answer
65k views

Lambda .Where() expression to return selected/flagged objects

In our software we enable certain features based on the existence of a flag. The Flags class is a static class used to determine the existence of such a flag. I ...
Kevin McCormick's user avatar
5 votes
1 answer
3k views

Getting items with overlapping DateTime using Linq

I have a live chat database and I am trying to get an idea of how many concurrent chats staff are taking. I'm not sure of the best way to report it so I have decided to get a list of chats for a given ...
TheRealTy's user avatar
  • 183
5 votes
1 answer
396 views

Merging trips to the same location with overlapping dates

I have a SQLite database that only contains the holidays for 1 user. I have a new Trip object (newTrip) that has a ...
Percy's user avatar
  • 193
5 votes
1 answer
135 views

Categorize episode-file names - Follow up

This is a follow up to this question. I have implemented changes to the code as they were suggested in the previous question and have made a few changes of my own. But it has been mentioned that the ...
Paras's user avatar
  • 585
5 votes
1 answer
507 views

Using LINQ to output SQL data from two tables into XML

I am very new to this. Hope someone could help me suggest how to improve the code. I have two tables where I need to get the SQL data and output it into XML format. I am using LINQ method. Below how ...
C Python's user avatar
5 votes
2 answers
797 views

Using Linq syntax, how can I remove the select n+1 issue in this method?

I have the following code in a validation module. It works the way I want it to, but it has an obvious select n+1 problem. I would like to refactor this code to make a single call to the db to perform ...
NotMyself's user avatar
  • 151
5 votes
1 answer
555 views

ListBox Update Handling

I have UserGroups for Users to be assigned to in a ListBox in HTML form. Items from listbox can be multi-selected or completely ...
lbrahim's user avatar
  • 353
5 votes
1 answer
89 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 ...
ValarMorghulis's user avatar
5 votes
0 answers
134 views

Implement Sudoku using LINQ

WiKi and GitHub. Sudoku rules are being checked with the following tests: ...
Dmitry Nogin's user avatar
  • 6,131
4 votes
5 answers
20k views

Convert Sql LIKE to Regex

I have a bit of code that converts a Sql Like expression to a regex expression for the purposes of a Linq to objects Like extension method. For some time I have ...
dkackman's user avatar
  • 161
4 votes
3 answers
10k views

Setting output parameter inside LINQ select

Is there a way to reduce the number of lines by setting the output variable inside LINQ select statement? How would you do it? ...
Hassan Humayun's user avatar
4 votes
3 answers
8k views

Factoring WHERE clauses in IQueryable

I recovered some spaghetti code and I have to refactor it. I do not want a method with over 200 lines, for me it is not object oriented programming. I am trying to ponder on the question and would ...
AED's user avatar
  • 207
4 votes
1 answer
1k views

Fetching data from a database

I am fetching data from the database using Entity Framework and Linq queries. I am wondering about the performance of getting data. I just want to check whether or not a ...
fhnaseer's user avatar
  • 191
4 votes
2 answers
289 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
3 answers
163 views

DistinctCount extension method

Here I go again. I have been finding a fairly common pattern in business logic code. And that pattern looks like this: ...
Jesse C. Slicer's user avatar
4 votes
2 answers
1k views

Two functions to impose order on queries

I am writing a c# program to build generic sort algorithm on a request to a collection of data. The data needs to be sorted based on the supplied columns.I am using Entity framework and Expression ...
rednerus's user avatar
  • 149
4 votes
2 answers
2k views

Simplify a complex LINQ query

Any suggestions how I could simplify this LINQ query? ...
JKor's user avatar
  • 151
4 votes
3 answers
3k views

Is ToIEnumerable<T> good practice?

I have an extension method that does this: ...
Amir Rezaei's user avatar
4 votes
3 answers
305 views

Finding the string from the list of array objects

...
Nɪsʜᴀɴᴛʜ ॐ's user avatar
4 votes
2 answers
12k views

Poker Hand Evaluator Challenge

This week's review challenge is a poker hand evaluator. I started by enumerating the possible hands: ...
Mathieu Guindon's user avatar
4 votes
2 answers
17k views

Search and filter in MVC3 Razor using Linq

This code works fine, but I just don't like all the if else. If I keep adding field to filter, it's going to get messy. I am not using EF and cannot on this. ...
Stone Temple Aviators's user avatar
4 votes
3 answers
4k views

C# + Linq - grouping objects by frames of time found in the data

A bit of background. In the application I work on there are emails sent to notify users about articles they need to review. Each email+recipient pair is stored in database and may be assigned a ...
jakubiszon's user avatar
4 votes
2 answers
40k views

Linq-to-Sql Contains an int? inside a list of int

Curious if there is a better way to write a repository method that receives argument List<int> and checks if the database ...
christo8989's user avatar
4 votes
2 answers
920 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
531 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
4 votes
2 answers
642 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 ...
Graham Parker's user avatar
4 votes
4 answers
1k 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 ...
Delfino's user avatar
  • 509
4 votes
2 answers
3k views

Optimizing join statement

I have this piece of code: ...
Srcee's user avatar
  • 251
4 votes
3 answers
31k views

Joining two IEnumerable<T>

I'm trying to merge two nodes. Basically, the idea is to take all children in left and new ones in right. Is there any way to get rid of toAdd variable and do it in ...
Ankush's user avatar
  • 285
4 votes
2 answers
179 views

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

I have the following collection : ...
tigrou's user avatar
  • 421
4 votes
3 answers
12k views

Splitting a list of numbers into multiple lists

I need split the list I get from the select into multiple list so I can use Parallel.For() to generate the next query in different threads. I create the main list ...
Juan Carlos Oropeza's user avatar
4 votes
3 answers
689 views

Concatenating two IEnumerables with a limit

I've been playing around with generators, generics and extension methods in C# (5.0) and wanted to create an extension method for IEnumerable, which would append ...
overactor's user avatar
  • 654
4 votes
2 answers
393 views

Wordy LINQ for XML word list

This code works as intended, however, I am sure that there is a way to condense the xmldataLoad method. If someone could maybe explain a better approach than what I ...
Jesse Glover's user avatar
4 votes
2 answers
212 views

Ordering filtered results

I have the following method which under code review gives me a CA1502 avoid excessive complexity error (although if I suppress the message it will build fine): ...
Pete's user avatar
  • 641
4 votes
2 answers
11k views

Flatten a tree to a collection of nodes

I have implemented simple tree class as follows: ...
Nick Udell's user avatar
  • 5,197
4 votes
1 answer
1k views

Transliterate between Cyrillic and Latin scripts

I want to get a code review on the following transliteration code. I wrote it because there were some libraries that I have tried and they were specifically failing with the name "Yuliya" ...
nop's user avatar
  • 739
4 votes
2 answers
1k views

Big O notation for Reverse String

I have here some methods which reverse string characters. Example if given string is "HELLO", it will returns "OLLEH". Are my big o notation for these approaches correct? And which approach is the ...
Steve Ngai's user avatar

1
3 4
5
6 7
13