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

learn more… | top users | synonyms

1
vote
1answer
51 views

Longest palindrome in a given string using LINQ

Problem:I need to write an algorithm that will return length of longest possible palindrome from a given string. So if the input is aabbbccdfg Program output should be 7. //-->[cabbbac] Can someone ...
-1
votes
0answers
20 views

.NET - LINQ: Using abbreviations [on hold]

When using LINQ. What is your approach to abbreviations? Is it OK to use abbreviations when you write LINQ? Alot of Microsoft's samples uses abbreviations but my personal experience tells me that ...
0
votes
0answers
26 views

Is this pattern for passing a LinqToEntities connection safe? [closed]

I've written a Data Access Layer for an MVC app I'm working on. Several Controller methods call several functions from the Data Access Layer. If more than one function is called, I initiate the ...
5
votes
1answer
62 views

Grouping queries

I have a list of Options. From that list: First I want to get only Drink (the where clause). Then I want to group them by their SortOrder (range of 100). I can ...
2
votes
3answers
139 views

Compare collections

I have two Collections and want to compare them. ...
0
votes
1answer
58 views

Efficient use of LINQ - Indexing

I have a Class with a List of objects, and those objects contain a list which has lists to objects in the first class, and I'm trying to quickly index them. Simplified: ...
0
votes
1answer
50 views

Reduce nesting of for loops to increase efficiency [closed]

I need to optimize this code so it can execute faster, even if that means using more memory: ...
2
votes
0answers
54 views

Improving LINQ expression with inner method call and switch statement

I have the following class which returns an expression that then returns data. It seems a tad over complicated and I'm pretty sure LINQ has something to offer that makes my life much easier. But I ...
1
vote
1answer
52 views

LINQ grouping and sum

I have 4 properties which values I generate using LINQ: ...
5
votes
2answers
106 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 ...
0
votes
1answer
43 views

Remove particular element from an array and return indices of other elements

I'd like to get the indices of elements of an array with particular element. Is it okay or, or how can I make it even better? ...
1
vote
2answers
268 views

Calculate Total of Items in List

I would like to convert the following procedure to use Linq, but I'm not sure how to accomplish it, ForEach or Sum? ...
1
vote
1answer
59 views

Performance shifting for SQL Database and Linq memory grouping

I am messing around with shifting between stored procedures and business layer EF getting data rapidly then processing in memory. This works and on a static data range of 3 months I get execution ...
3
votes
2answers
76 views

Flatten Hierarchical Data with LINQ

I have a model with a hierarchical structure like this: ...
2
votes
1answer
62 views

C# sitemap crawler

Basically my code piece is a sitemap crawler - it opens sitemap, that contains sub-sitemap listings from - to a datespan. It opens sub-sitemap and gets all the URLs (most of them are seourl's, but not ...
6
votes
4answers
1k views

Using LINQ or Lambda instead of nested and multiple foreach statements

I want to use a better syntax than nested foreach statements to overwrite the initial list with items from the second list. In the code below: I want to ...
10
votes
2answers
264 views

Get result from UI thread to non-UI thread when using await Task.Run

I have an application where I use Task to run an operation. During the operation, there can be a problem which will need some user interaction (continue or not). I ...
1
vote
1answer
83 views

Optimizing my program by accessing data locally instead of a remote database

I have a database with 4 tables filled with millions of rows. I have my program run on several computers computing data and then returning it to the database. The huge bottleneck in my program design ...
3
votes
2answers
109 views

Getting column values from a datatable

Is there a way I can make the code compact and with fewer ifs? ...
8
votes
3answers
480 views

Get values between two dates

I have a search form where users can enter ValidFrom and ValidTo dates, There are three conditions: ...
3
votes
2answers
177 views

Uppercase the initial char of every string in a list

My problem is that I have a sequence, potentially infinite, of strings. Let's suppose it to be {"Mickey Mouse", "Bugs Bunny", "Winnie the Pooh"} I have to make ...
4
votes
2answers
182 views

Query results with many to many and some parameters using Entity Framework in a more efficiënt way

I've created a working query in Entity Framework and I'm curious if there's a better way to do this. Since there's a lot of field on my models, I will only publish the relevant ones here. My Models ...
15
votes
5answers
2k views

Linq me a FizzBuzz

I got this requirement recently: Write some code that prints out the following for a contiguous range of numbers: the number 'fizz' for numbers that are multiples of 3 'buzz' for numbers ...
2
votes
2answers
164 views

Timeouts when calculating stock ratings using LINQ

I'm getting a lot of timeouts with the following code and I'm running this method around 10,000 times so I need to figure out how I can optimize this so the timeouts will stop. I am getting timeout ...
3
votes
3answers
110 views

LINQ foreach - error handling and general improvement

I'm looking for two kinds of feedback: Is there a better way of doing what I'm attempting to do? Any obvious weaknesses that could potentially cause problems? The code in question (I've broken it ...
10
votes
3answers
335 views

Read/write to XML using LINQ

This will compile, but I'm thinking that this implementation of read/write is very hard coded and would not be easily adapted to larger situations where large XML documents are being processed or if ...
2
votes
2answers
149 views

Divide certain distinct row values into separate columns

This might be difficult for me to describe clearly but I will try anyway. Also note that this is entirely speculative; it might not even be able to run any faster (that is why I am asking). This is ...
5
votes
3answers
144 views

Code redundancy issue while feeding dropdownlists

I have a dashboard to manage a learning center system. There are scenarios like admin create learning center and define a classroom in it and then assign some courses in it and assign students to ...
14
votes
9answers
670 views

How can I refactor to avoid repetition finding the index of strings in a list?

I have a list of strings where I want to find the index of a first- and second-choice video compressor. Logic: If the first choice is available, return its index. If not, and the second choice is ...
1
vote
1answer
78 views

Simplification LINQ query and other code

I need to simplify the below code as well LINQ query: ...
1
vote
2answers
469 views

Split a list into equal parts that using LINQ in a way that has good performance

So I have a method that looks like this: ...
5
votes
2answers
173 views

Best way to get the list of XML files

I'm a newbie in the use of LinqToXml and I wonder if I can improve this snippet. ...
3
votes
3answers
255 views

WorkGroup Data Service with JSON / Web based API

I'm wondering if this code can be made more clear and fluent: ...
3
votes
2answers
145 views

Sorting by patients' name or birth

Is there a way to write this simpler? ...
-1
votes
2answers
99 views

Sorting array with respect to two properties

I'm sorting with respect to Width and Length. However, Width has the significance ...
5
votes
1answer
585 views

Sudoku Solver - Recursive Solve

Any ideas on making my code a bit more clean and efficient? Any criticism is appreciated. I don't like that I'm calling my lengthy DeepCopy method so many times, ...
3
votes
1answer
58 views

Parent with N-Childs where each child can have N-Childs

I know my question sounds strange but I have a situation in which I have Parent Data which can have 'N' Childs and each child can further have N-Childs and so on. So its Like. Parent a. Child ...
2
votes
2answers
211 views

Linq C# pulling from table row into input fields

Today is the first time I've used Linq, so I wanted to get a code review on this and make sure I'm going about it correctly. I'm filling text boxes and dropdown lists from a table row. ...
0
votes
1answer
107 views

Approximate integral in one line of code

This is what I came up with: Version 1: ...
1
vote
1answer
99 views

LINQ method to create objects of different types

I have the following code inside a method: ...
5
votes
3answers
93 views

Summing some datum for requests in each domain that fall in a date range

I have a LINQ query which works fine. I am however very interested to understand if this can be written in a more optimum way... ...
21
votes
2answers
368 views

Wait, is this… LINQ?

Context I'm working on a little project that consists in a series of Microsoft Excel add-ins (.xlam). The code being submitted for review here, is located in the ...
2
votes
2answers
159 views

Improving the performance of Linq based solution

Again, out of fun on saturday night, I decided to solve the following problem from CodeEval. The challenge is finding the index of the lowest unique number. ...
3
votes
1answer
259 views

Insert missing records in a list with LINQ

We have a table with periods, and other child tables with these periods and values for combinations of product + location. Based on selected periods, I would like to add any missing rows in the child ...
3
votes
1answer
185 views

Efficiency of nested LINQ foreach loops

I've been working on an older project with framework is 3.5 as the target. There is a new user control that displays a list of data from a web service. I hit the web service (Soap/XML) and deserialize ...
8
votes
3answers
349 views

Indentation on a long (ish) linq chain

I have some code that loops through directories named for years (e.g. /2011/, /2012/ etc) which each contain files whose names ...
5
votes
2answers
104 views

Longer LINQ Chaining

Anyone have ideas on how to improve this code at all? ...
-2
votes
2answers
176 views

Optimizing nested loop for an array within a list [closed]

How can I optimize the following code, with LINQ or some other trick? Bird is a class which has different properties id, name, etc and Nest which is an array of places. ...
4
votes
1answer
129 views

Returning a list of income for a month

My current code takes 2.7-4.5 seconds to complete, is there any way to make it faster? I need to return a list of the income in all days in a month. My idea was to loop through the days of one ...
2
votes
1answer
520 views