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

learn more… | top users | synonyms

5
votes
3answers
80 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... ...
0
votes
0answers
40 views

Linq to SQL ('select * from table').Count() vs (“select column from table”).Count() [migrated]

I am writing some linq queries where I came across following scenario: I want to fetch records from DB using Linq bases on some filter Here I want to take all record count also, so I did like ...
17
votes
2answers
189 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
110 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
58 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
81 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
289 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
92 views

Longer LINQ Chaining

Anyone have ideas on how to improve this code at all? ...
0
votes
0answers
33 views

Looking for a more efficient way to perform this query [closed]

The following query works, but there must be a more efficient way to get the data needed. I'm looking for the sales from a complete client listing for a specific user for last year and this year. ...
-2
votes
2answers
134 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
86 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
88 views
2
votes
1answer
80 views

LINQ query using StartsWith and Contains to limit the results for an autocomplete field

As a source for a jquery-ui autocomplete field, I've written this action: ...
3
votes
1answer
85 views

Find the number of Colleges offering Combinations of Levels: Performance

I have been using entity framework 5 as DataAccess layer for my application. I have a case where there are a set of Levels offered. And I have a set of ...
11
votes
2answers
217 views

CSV reader using StreamReader and LINQ

Mostly due to readability, I am using the following code to find a specific csv file on a drive read that CSV file using a streamReader parse it into a ...
-1
votes
0answers
47 views

Optimizing searching and comparisons [closed]

There are big words, small words and "rarity" of the small wards. I have to find for each small word that big words, which starts with this small word. And take 10 of them with top rarity. I ...
5
votes
1answer
92 views

Producing the intersection of several sequences

Based on this SO answer I have created a method that produce the set intersection of several sequences: ...
3
votes
1answer
81 views

Compare / Join two object collections LINQ

I have two csv files that I need to compare and merge together. There is a 'big' list with many records and columns of data and a 'small' list of the desired records and some additional data. The ...
4
votes
2answers
73 views

Is this the optimal way to write “find these IDs in a list of objects” using linq?

I've got a situation where I have a list of Organizations (code to follow), and a user has a list of OrganizationIds (ints). I ...
0
votes
3answers
99 views

Linq query performs poor according to performance analyzer in VS2012

I've a Linq query that performs poorly: ...
5
votes
1answer
81 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 ...
7
votes
2answers
150 views

Convert a list of sets into the minimum list of non-intersecting sets

I have a list of sets. The same items may appear in multiple sets. I want to transform this into a new list of sets where: Each item only appears once in the entire list of sets. For each set in ...
1
vote
1answer
59 views

Improving iterative manipulation on XML elements

In this reply, there's an example of how to remove a node from a XML structure. ...
1
vote
1answer
102 views

Dynamic Linq from string with EF

I wrote an EF browser to dynamically navigate through entities. Beside basic properties of system types, each entity can have several singular or plural navigation properties. In order to support all ...
2
votes
1answer
78 views

Tasks and WaitAll\WhenAll

Could you help me to speed up/optimize this code: ...
1
vote
4answers
94 views

Checking if there are tags or categories in the database

The code below is used to check if there are tags or categories in the database. If they exist, they are not added to the database, otherwise they are added. Is this code efficient and easy to read? ...
13
votes
3answers
831 views

Using C# properties for simple operations, where should I draw the line?

Should I be putting Linq statements inside of an objects properties? Is that a best practice or is that a no no? Also if that is ok, where do I draw the line with this? I assume db access is ...
2
votes
1answer
45 views

Is there a better way to handle multiple join statements in a linq query? [closed]

I am rewriting a VB.NET app into C#. I won't subject you to the original code. I am mainly looking for a better way to handle all the join statements that are being done. I am dealing with a legacy ...
10
votes
1answer
97 views

Refactor VB.NET to C#.Net using Linq

I am rewriting a VB.NET application in C#. I will not subject you to the original code because it's pretty messy. Below is the converted C# code: ...
4
votes
4answers
309 views

A better way to do LINQ projections

I was wondering if there's a better way of doing LINQ projections than what I'm doing below. This method is one of many methods creating a view of an object tree. The first thing that I don't like is ...
3
votes
1answer
44 views

Updating properties and states

I am rewriting a VB.NET application in C#. This code was originally done in 50 lines and I am trying to clean it up. As you can see I have gotten it down to 10 but I still feel its ugly. I want to ...
3
votes
1answer
67 views

Changing these two functions into one function

I have two functions that are similar. The only differences is that they're using two different models. How can I change them into one function? ...
5
votes
1answer
74 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 ...
7
votes
3answers
134 views

Searching all diagonals of a 2D M x M array

I've started writing a piece of code to help me search for an object in all the objects found in the diagonals of an M x M 2D array. Though the code works, I'd like to know if there is a way I can ...
1
vote
1answer
76 views

Making an email text-parser generic using PredicateBuilder

I have some code that reads an email from a text file, parses the text, removes some lines (the 'cc' and 'to' lines) and then finds the line numbers of various phrases (e.g. "Regards", "Thanks") and ...
3
votes
1answer
58 views

Optimisation XML handling within vb.net application

I need to optimize this snippet to be faster: ...
10
votes
1answer
538 views

Update first and last item in List<T>

I am trying to do the following. I have a list of Custom objects: ...
4
votes
3answers
344 views

Refactor C# Linq code to reduce duplication

I currently have the below code: ...
5
votes
1answer
63 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 ...
4
votes
1answer
180 views

IndexOrDefault that functions like FirstOrDefault

I don't know why this is not in the .NET Library, but I need to be able to use an index against a list and not have it throw an exception if it is outside the bounds of the list. This is what I came ...
6
votes
4answers
183 views

Simplify LINQ to Create Step Values

Assume the following definition: ...
7
votes
4answers
356 views

File text searcher

I have a working version of a logfile searcher that targets a specific directory by extension type, and searches the files for certain words. I'm wondering if my method is the most efficient ...
5
votes
1answer
103 views

Nested LINQ Nightmare, calculating %completed

This code horrifies and scares me. I wrote this. ...
5
votes
1answer
93 views

Combining List<>.ForEach and List<>.Zip

I have three lists, and I need to operate on the ith element of each list simultaneously. ...
4
votes
1answer
915 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 ...
5
votes
2answers
382 views

Efficient way to get every unique combination of “Pick 1 number from each Group of Numbers”

My question is: Using C# and/or Linq, how can this existing code be improved to be more efficient? (My "Complex" example takes about 5 seconds to run, how to make it faster?) What the code is ...
5
votes
2answers
259 views

Adding object to database, using linq or sql connection

I have a table called tblDelegates in my database which I need to populate with some data. I have created a class called Delegates which has various properties to ...
4
votes
2answers
108 views

Create a LINQ Killer Sudoku Cage Solver

When playing Killer Sudoku I find myself repeatedly writing stuff like this: 12/3 921 831 741 732 651 642 543 and then crossing out the combinations that include ...
6
votes
1answer
181 views

Refactoring a LINQ query that (sometimes) returns null

I have the following LINQ query that should return a result for each Request. I'd prefer to have the query translated to ...
7
votes
3answers
778 views

Get distinct combinations of numbers

The below code returns all distinct combinations based on the logic that 1,2,3 = 3,2,1 = 2,3,1, so it only returns 1 instance of that set of numbers. ...