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
1
vote
1answer
96 views

Reading data from a CSV and pushing it to a Salesforce application

I'm trying to write code that reads data from a CSV and pushes it to a Salesforce application using the API. My code processes the data in a for loop, but it takes a long time (3 hours) to run the ...
0
votes
1answer
65 views

Merging every two objects into single single object making group by a property C# LINQ [closed]

I have a object list like below. I want to join every two rows into single row based on column B. It is sure that only two rows would be there for every single column B value. Input Output However, ...
0
votes
0answers
12 views

Make a method that uses Expression<Func<T>> for filtering and sorting more flexible

I have a method in a service that performs a Linq-to-SQL query: ...
-2
votes
1answer
96 views

Can I refactor my code anymore? [closed]

I have written one method; however I feel I can refactor it even more but not sure what Can someone help me here? ...
0
votes
1answer
77 views

Linq query to merge overlapping elements

I have this class representing a period of time: ...
1
vote
0answers
48 views

Optimizations on a function that fIlters a list of connections

Hello fellow programmers, I am currently implementing a function and wanted to know if there was anything I could change to simplify the code, make it more readable, or to optimize the running time ...
5
votes
1answer
343 views

Displaying information about an order when selection changes

I feel like just because the below works doesn't mean it is correct, I want to improve it but I can't really figure out how. Besides the fact it is down right ugly I feel the performance could be ...
6
votes
2answers
698 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
117 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 ...
2
votes
2answers
1k views

Filter out string sections

I have a helper method to clean up a string and remove pieces that I will be generating again. (defined by the "SpecialKey" Constants) but I've never been real happy with the code. Although I find it ...
0
votes
1answer
53 views

How to make this code follow Solid Principle C# [closed]

Currently I have this code: ...
3
votes
2answers
8k views

Flatten a tree to a collection of nodes

I have implemented simple tree class as follows: ...
1
vote
1answer
88 views

Should I use and loop, or just a loop? [closed]

I have this code: ...
1
vote
2answers
79 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. ...
14
votes
2answers
9k views

Generic Calculator and Generic Number

.NET does not support generic numbers. It is not possible to enforce a generic method with generic argument T that T is a number. The following code will simply not compile: ...
0
votes
2answers
96 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
638 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
112 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
627 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!...
6
votes
5answers
397 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. ...
5
votes
3answers
194 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 ...
3
votes
5answers
14k 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 ...
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
594 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
42 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
54 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
113 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
231 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: <...
5
votes
4answers
13k views

Return IEnumerable<KeyValuePair> from a private method; use Dictionary or anon. type?

Is it okay to return IEnumerable<KeyValuePair<string, string>> from a private method instead of returning a read-only dictionary? This allows for ...
4
votes
3answers
266 views
4
votes
3answers
138 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: ...
9
votes
2answers
5k views

Query Builder pattern with use of FluentApi

Recently, I've come up with an idea of building a custom query builder combine with FluentApi. Expected usage: ...
6
votes
1answer
3k 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
516 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 ...
4
votes
3answers
10k 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 ...
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
477 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 ...
3
votes
1answer
2k views

LINQ statements that aggregate sums from a List of objects

I'm packaging data for use in a JavaScript charting library that expects a somewhat odd structure of data in which there is an array of labels and an array of ...
2
votes
0answers
72 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
54 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
92 views

LINQ extensions for sequence comparing

The desired behavior would be: ...
3
votes
1answer
207 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
2k 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 ...
7
votes
2answers
197 views

Iterate only once using LINQ

Funny thing, the following test works: ...
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: ...
5
votes
0answers
108 views

Implement Sudoku using LINQ

WiKi and GitHub. Sudoku rules are being checked with the following tests: ...
0
votes
0answers
65 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 ...

1
2 3 4 5
12