Questions tagged [linq]
Language INtegrated Query (LINQ) is a Microsoft .NET Framework component that adds native data querying capabilities to .NET languages.
592
questions
6
votes
2answers
669 views
C# - Linq - Techniques for avoiding repeating same pieces of code
I am writing a piece of code for C# Web Api, letting the clients to pass a column name and sort direction as parameter.
Although there are, like, 30-ish properties, so the following code (despite it ...
1
vote
1answer
109 views
Eliminating repetitions of subsequent items in a list
I would like to convert a list A
A = {1, 12, 3, 3, 3, 8, 5, 5 }
into list B
...
0
votes
1answer
51 views
1
vote
2answers
76 views
Finding duplicates in multiple lists for configuration validation
I have created helper class for configuration validation, the main purpose is to find any human "errors"
in the configuration for the app.
the case is that any type of "message" ...
-1
votes
1answer
85 views
Simplifying for loops that includes conditions with better linq queries
The code below selects all items that are locked. How can I optimise it?
ShopItemData doesn't contain a field for locked/unlocked.
...
0
votes
2answers
95 views
Optimizing database access using LINQ [closed]
I have the following method that I am trying to optimize. Currently, the method works great, however, it takes a little over 3 hours to complete. I feel like, using some nifty LINQ joins, it should be ...
3
votes
1answer
199 views
A simple method to execute Entity Framework Core queries in parallel
As you might know, EF Core does not support executing multiple queries in parallel on the same context using something like Task.WhenAll.
So you have to write this ...
4
votes
0answers
109 views
Repository pattern method implementation with entity framework and C#
I have two entities in my database: Employee and Shift. I want to implement a C# repository pattern method, that given two ...
6
votes
2answers
327 views
c# list object with view model child list
I am trying to build this view model that has a ChildViewModel and this was the only way I was able to get it working. Any advice on how to make this code; cleaner, more effective, just overall better!...
5
votes
3answers
129 views
Creating a CSV stream from an object
I have this code that gets a CSV string from a list of objects where the first row in the string is the object's properties and the rows underneath are the properties values. I then create a ...
2
votes
1answer
49 views
How do I make multithreading in sending large file from FTP to Azure large files faster
Currently, I have a code which downloads a file from FTP to local hard disk. It then uploads a file in chunks to Azure. Finally, it deletes the file from local and ftp. This code is very slow though. ...
5
votes
1answer
177 views
Compare List to Enum Where Contains Any
I have a List that I want to compare to an Enum.
If a.Value is found in the Enum we return <...
2
votes
1answer
36 views
Iteration over an XDocument based on some existing elements and conditions
I wrote this piece of code which works as expected:
...
1
vote
1answer
53 views
Filter linq query
Any advice on how to make this code; cleaner, more effective, just overall better!
Program has three options that can be passed int NewsId,Year and CategoryId. I collection all the data and then do ...
1
vote
2answers
108 views
Building a Word document containing two different tables
I am trying to generate a Word document with two different tables inside it. For this purpose I have two similar methods where I am passing word document reference and data object and table to the ...
1
vote
2answers
149 views
Protein Translation - Translate RNA sequences into proteins
RNA can be broken into three nucleotide sequences called codons, and then translated to a polypeptide like so:
RNA: "AUGUUUUCU" => translates to
Codons: <...
4
votes
3answers
264 views
4
votes
3answers
134 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: ...
6
votes
5answers
356 views
Find greatest number in array that is a product of some two elements in the same array
Given an array a, find the greatest number in a that is a product of two elements in a. If there are no two elements in a that can be multiplied to produce another element contained in a, return -1.
...
6
votes
1answer
2k views
Async selector in LINQ
LINQ Select usually works like this:
IEnumerable<Task<int>> res = new[] {1,2,3}.Select(async i => i);
I would ...
4
votes
2answers
364 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 ...
6
votes
1answer
103 views
Picking a random neighbouring cell, but only picking previously-visited ones if there aren't any unvisited
I'm creating mazes, and have a Cell class (only relevant code shown)...
...
1
vote
0answers
322 views
SelectAsync With Max Degree Of Parallelism
I have been looking for the best approach to creating an extension method that would give me the ability to select in a linq query using async/await with a max degree of parallelism. I'm aware that ...
2
votes
0answers
67 views
Generic search service to filter entries in lists
I'm in the process of implementing a fully generic service to filter out entries (of any type), which are contained in a ICollection.
As it is generic, without any ...
1
vote
0answers
47 views
Getting all descendants IWebElements (using XPath) is too slow in Selenium
Well, I'm working with Selenium to scrap a webpage that has obfuscated class names (example <div class="example-gHJkLM">...)...
So I needed to create an ...
1
vote
0answers
86 views
get better performance [closed]
I have this code that works, but I'm sure that it can be done better, any suggestions?
...
2
votes
0answers
91 views
3
votes
1answer
160 views
C# Linq search list within list
I am writing a domino draw game in C# and would like to know if there is a simpler/better way to know the player that has been dealt the highest double bone (where x equals y) and what bone it is:
<...
4
votes
3answers
1k 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 ...
18
votes
6answers
6k views
Solving Fizz Buzz using LINQ in C#
The Fizz Buzz challenge is well-known and should not need any explanations, right?
I recently got a bit bored and came up with a solution for Fizz Buzz using LINQ and even asynchronous code and a lot ...
12
votes
2answers
1k views
Given an array A[] and a number x, check for pair in A[] with sum as x
LINQ/FP style:
Assert.IsTrue(new[] {1,2,3}.AnyPairSum(4));
Where:
...
4
votes
0answers
107 views
Implement Sudoku using LINQ
WiKi and GitHub.
Sudoku rules are being checked with the following tests:
...
0
votes
0answers
62 views
GCD Groups with list
We have a list.
divide the list element into two groups such that when the product of the numbers of two groups is taken and their GCD is calculated, it came out to be 1. Answer the number of ways in ...
7
votes
2answers
184 views
4
votes
1answer
93 views
4
votes
2answers
133 views
Finding which items have at least one common value with other items
I have the following collection :
...
1
vote
1answer
98 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:...
8
votes
3answers
3k 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 ...
4
votes
2answers
123 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:-
...
4
votes
2answers
191 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 ...
5
votes
1answer
309 views
Make utility using LINQ
Make() takes projects with a list of tuples representing project references in the form of (Dependency, Dependent) and returns ...
6
votes
4answers
3k views
LINQ for generating all possible permutations
Permutate() is supposed to generate all possible permutations of the source sequence:
...
3
votes
1answer
116 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 ...
9
votes
4answers
996 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:
...
1
vote
0answers
333 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 ...
17
votes
3answers
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 ...
5
votes
2answers
127 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 ...
7
votes
5answers
655 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 ...
5
votes
3answers
493 views
SkipLast of an IEnumerable<T> - Linq Extension
As my answer to this question, I came up with this solution:
...
2
votes
1answer
132 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 ...