Skip to main content
Share Your Experience: Take the 2024 Developer Survey

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 votes
1 answer
225 views

Optimizing LINQ Query on C# Web API

Can someone help me optimize this code especially the LINQ query. It takes 8-12 seconds just to return a response when I'm calling the endpoint. Its super slow, and my whole endpoint call is taking ...
10 votes
3 answers
5k views

Filter out nulls from sequence of nullables to produce sequence of non-nullables

While introducing nullable reference types to our enterprise application's codebase, I found that we are often using LINQ on sequences of nullable reference types where we filter out the nulls using <...
1 vote
1 answer
20k views

Passing model to _layout.cshtml

I have login page that looks like: It has a ViewModelBase and a ViewModel as: ...
2 votes
1 answer
194 views

IEnumerable<T>.Tee implementation

I am trying to write A C# version of a method in the Java Stream API called Collectors.teeing() (It's like Aggregate but with multiple accumulator functions), just for educational purposes. I want to ...
7 votes
3 answers
26k views

Joining to in memory List

I have an in memory list that I am joining to results from a query using entity framework. My list will most likely never be greater than 2500 records. The results from the database can fluctuate, ...
6 votes
2 answers
4k 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!...
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" ...
19 votes
7 answers
15k views

Optimizing List<string> performance

I have a List<string> being stored in my cache with about 600K members. I want this to act as the backend for an Ajax autocomplete box. It's accessible ...
3 votes
1 answer
116 views

"Select followed by First" versus "First followed by Select" when summing the data for a student

I am wondering which one I should choose between the following two options when I need to calculate the sum of Data of the student with ...
10 votes
1 answer
264 views

Linq-to-Sage Implementation

Following-up on my last question where I wrapped the Sage API with a familiar IRepository interface, I decided to push the abstraction a step further, and... ...
1 vote
1 answer
1k views

Basic ATM Software from a Udemy Project

Recently starting to learn programming, I'm looking to move to making larger projects and am just picking up the basics now. I have a feeling this code sort of missed the point? Am looking for ...
2 votes
2 answers
113 views

Project sequence to multiple sequences using LINQ (or extension methods)

I'm creating a method that expands a sequence. This is a sample of how it works: Input: {1, 2, 3} Output: {1}, {1, 2}, {1,2,3} So far, I've been able to solve the ...
3 votes
4 answers
8k views

Finding the minimum difference in a list of numbers

I have written following code to find the minimum difference from a list of numbers. Because I am using a loop once and LINQ again to find the minimum, the algorithm is O(N2). Can you please tell me ...
1 vote
2 answers
574 views

Find the newest file that contains a specific string in every subdirectory of the path using the least resources

I have a server side logs folder that contains many hundreds of logs most of which are in subdirectories according to the machine the logs have come from. The task is to extract the full path of the ...
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 ...
5 votes
3 answers
32k views

Recursive method turning flat structure to recursive

I often end up working with systems where the data is delivered with some Id property and possibly a parentId prop, but never do ...
1 vote
0 answers
133 views

Getting all descendants IWebElements (using XPath) is too slow in Selenium

Well, I'm working with Selenium to scrape a webpage that has obfuscated class names (example <div class="example-gHJkLM">...)... So I needed to ...
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 ...
27 votes
4 answers
102k views

Filtering a list of vertices that lie inside a cylinder, with and without LINQ

Since I don't know how LINQ works under the hood, I can't decide what version is best to use in term of rapidity of execution. I've done some testing with my testing data (Point Cloud) but I can't see ...
0 votes
4 answers
2k views

Checking a value in a string array in C# [closed]

I want to see if there is a cleaner way to do this logic. I have a working sample: Same fiddle.net ...
1 vote
2 answers
348 views

Is there a way to use lambda function to get the list?

I have a data set. ...
1 vote
1 answer
367 views

Linq query to merge overlapping elements

I have this class representing a period of time: ...
11 votes
6 answers
8k views

PermMissingElem- find the missing element in a given permutation in C#

I just encountered this question in codility but apparently this question has been asked in java already (here, here). Task description A zero-indexed array A consisting of \$N\$ different integers ...
1 vote
2 answers
103 views

Is there a way to simplify getting the character that appears the most in a collection with Linq?

I have a collection of strings, all of which are three characters in length: ...
1 vote
2 answers
98 views

Efficiency of finding one database record using two ID's

I'm using C#, .NET Core and the entity framework and am currently working on optimizing various functions for better performance. One of the main functions is getting a calculation based on two ...
1 vote
1 answer
491 views

Is there a nice way to add unique items from inner collections using LINQ method syntax

Code ...
1 vote
1 answer
109 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
1 answer
5k 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, ...
-2 votes
1 answer
102 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? ...
1 vote
0 answers
54 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
1 answer
355 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
2 answers
1k 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
1 answer
141 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
2 answers
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
1 answer
62 views

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

Currently I have this code: ...
4 votes
2 answers
11k views

Flatten a tree to a collection of nodes

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

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

I have this code: ...
1 vote
2 answers
389 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" ...
0 votes
1 answer
187 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. ...
15 votes
2 answers
10k 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: ...
1 vote
2 answers
160 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 ...
4 votes
1 answer
6k 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
0 answers
141 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
5 answers
1k 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
3 answers
12k 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 ...
4 votes
5 answers
21k 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
1 answer
335 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
1 answer
8k 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
1 answer
1k views

Iteration over an XDocument based on some existing elements and conditions

I wrote this piece of code which works as expected: ...
1 vote
1 answer
74 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
2 3 4 5
13