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

learn more… | top users | synonyms

4
votes
1answer
79 views

Finding out which user has made the most progress

I have some code to accomplish the objective of finding out which user has made the most progress. Progress is measured in integer values, the higher the better. ...
1
vote
1answer
61 views

Get list of unique parents from childrens list

Parent has list of Children. I only have access to the list of children. I need to get list of unique parents from the List of ...
2
votes
2answers
52 views

Grab set of data from database that matches userid and return it to the view

I want to get the row of data that matches the user ID I have. Then I want to return that view to my view to be displayed in my textboxes for editing. Here's the action that gets called when a get ...
3
votes
2answers
81 views

Linq to entities query for donor registrations [closed]

I'm using Linq-to-Entities for querying, and MVC.NET and C# for coding. I'm trying to generate monthly donor registry report which needs donor count, donors who signed through web,donors who ...
4
votes
2answers
92 views

Wordy LINQ for XML word list

This code works as intended, however, I am sure that there is a way to condense the xmldataLoad method. If someone could maybe explain a better approach than what I ...
6
votes
1answer
79 views

Shuffling an arbitrary list or sequence

After reading this question I wanted to write a short example of how a list or sequence could be shuffled in .net. The result turned out to not be very short: Program.cs ...
13
votes
7answers
1k views

Imposing a sort order on a query

I've always been told "never use goto, there's always a better way" and for the longest time I just accepted it. Lately though, I've been running into such scenarios in which I have to repeat this bit ...
8
votes
2answers
893 views

LINQ query that filters elements from a list of object

I have two lists of objects Person and PersonResult. Both are linked through the property ...
4
votes
2answers
170 views

Ordering filtered results

I have the following method which under code review gives me a CA1502 avoid excessive complexity error (although if I suppress the message it will build fine): ...
1
vote
0answers
52 views

Populating Charts with Chart.js

I have a dashboard page which populates some charts. They execute a Linq query to then transform the data into Json to populate the Chart. These charts maybe used throughout the site, so I am ...
4
votes
2answers
130 views

Two functions to impose order on queries

I am writing a c# program to build generic sort algorithm on a request to a collection of data. The data needs to be sorted based on the supplied columns.I am using Entity framework and Expression ...
4
votes
2answers
85 views

Linq refactoring

I have some code that asynchronously load some point in chart when user drag it. ...
2
votes
1answer
55 views

Checking for user permissions

The idea here is we have Roles, Permissions, and a table called PermissionRoles that connect the two. So a Permissions can be in many Roles, and many Permissions can have the same Role. So what the ...
1
vote
0answers
127 views

Retrieving Primary Key from Entity Framework entity

Entity Framework (version 6) generates classes based on your tables that look like this (where each property represents a field in the table): ...
1
vote
0answers
35 views

Query against history table

I have this linq query that queries a table that retains any change history done to any of the tables is constructed like this: ...
-3
votes
1answer
65 views

Extracting properties from stories

I have a list of items, and a list of actions that extract data from those items. I iterate over the list of items and create a Dictionary for each item that has the data extracted from the item. I ...
2
votes
1answer
51 views

Convert two collections of different objects into a single collection

I am combining two lists of separate objects into a single combined list. The below code works perfectly but it is not the most elegant or efficient solution. Is there a better solution? ...
3
votes
2answers
148 views

Permutations in C#

I have a program that will get all possible permutations of a certain equation: A + 13 * B / C + D + 12 * E - F - 11 + G * H / I - 10 == 66 Where A, B....I is a value 1-9, and where each digit ...
3
votes
1answer
89 views

Extracting opening and closing times for each day of the week

I have these two methods: ...
0
votes
1answer
52 views

Repetitive code for a projected field in a lambda

I have a simple projection in my code. Taking away the majority of the fields which are not of interest, it looks like the following: ...
2
votes
3answers
113 views

Property Mapping with Reflection efficiency

I have an object that I am populating via mapping and lookup with Reflection: ...
11
votes
2answers
2k views

I had one job to do

The code I am working with: ...
2
votes
1answer
55 views

Query the context or resulting list

I was just getting some products using entity framework and was wondering which would be better to do when getting the results, or if there is no difference. Option 1 - Query the context directly ...
2
votes
2answers
230 views

Flatten a tree to a collection of nodes

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

LINQ to Entities query of tests for my classes, with many subqueries

This MVC4 controller method, which uses EF6, is taking a long time to run (over 2 seconds). I've added verbose comments for the purpose of this post only. ...
0
votes
1answer
107 views

Inserting employee records

There is nothing wrong, but is there any other nice way to re-write this program? ...
6
votes
1answer
137 views

Code Inspection: Procedure not used

Here is yet another piece of Rubberduck code, this time the nasty ProcedureNotUsedInspection class, whose role is to identify all procedures that are never called ...
2
votes
1answer
45 views

Extract incomplete weeks from a DateTime collection

The code below attempts to extract incomplete weeks from a List<DateTime>. For example, a list containing all the days in Jan 2015 would result in the 5th to ...
1
vote
1answer
110 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 ...
5
votes
1answer
72 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
164 views

Compare collections

I have two Collections and want to compare them. ...
1
vote
1answer
93 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
73 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: ...
3
votes
1answer
142 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 ...
2
votes
0answers
112 views

Grouping and summing values for food takeout

I have 4 properties which values I generate using LINQ: ...
5
votes
2answers
125 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
124 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
336 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? ...
2
votes
1answer
89 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
121 views

Flatten Hierarchical Data with LINQ

I have a model with a hierarchical structure like this: ...
2
votes
1answer
112 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
4k 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
388 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
91 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
434 views

Getting column values from a datatable

Is there a way I can make the code compact and with fewer ifs? ...
8
votes
3answers
1k 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
440 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
581 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
226 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 ...