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
81
votes
5answers
24k views

SudokuSharp Solver with advanced features

Even though it's the first time I'm writing something this "big", it feels like I know C# quite well (it is very similar to Java after all). It's been nice to learn LINQ also and I am very impressed ...
10
votes
1answer
224 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... ...
40
votes
2answers
4k 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 ...
17
votes
3answers
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 ...
6
votes
1answer
579 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 ...
3
votes
2answers
487 views

Countable and uncountable sets in .NET (IEnumerable and Predicate)

There is a full featured support of countable sets in .NET: IEnumerable<T>. What about uncountable sets; sets defined by predicate? How can they be ...
24
votes
5answers
16k views

Single line FizzBuzz solution in LINQ

Now FizzBuzz itself isn't a big challenge but I agree that it can be a good tool to see if someone can code or not. I wanted to practice my LINQ a little bit so here's my single line FizzBuzz ...
11
votes
6answers
3k views

Too Many Staff Meetings

I recently got in really deep on a question to find the overlapping meetings and I rewrote a bit of the code and added some things to the code, and I would just like a general review of my code and ...
7
votes
1answer
311 views

LINQ Provider: Supporting Projections

Up until recently, my LINQ-to-Sage provider didn't support projections, so the client code had to explicitly "transfer" to LINQ-to-Objects, like this: ...
11
votes
2answers
3k views

Poker Hand Evaluator, take 2

This is following up on my previous attempt, which was admittedly done fast and not-so-well. This code attempts to allow comparing two poker hands to determine a winner, not only evaluating a given ...
8
votes
4answers
12k views

Filter data with optional parameters

I would make a filter to filter my data using next parameters: First name Last name Language Profile A minimum date of registration A maximum date of registration Success All filter options are not ...
14
votes
7answers
4k 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 ...
10
votes
1answer
196 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: ...
10
votes
3answers
2k views

Tracking Entity Changes (not EF)

So, I kept refactoring my Sage300 API wrapper - I wanted the client code to feel just like using Entity Framework - this is the closest I got to it: ...
5
votes
3answers
197 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 ...
5
votes
2answers
373 views

Getting list of daily team goals

The old code I had before was atrociously slow but after some advice and research I was able to take a 2-5 minutes run time down to about 5-30 seconds. That is acceptable, but still looking to have ...
4
votes
3answers
6k views

Factoring WHERE clauses in IQueryable

I recovered some spaghetti code and I have to refactor it. I do not want a method with over 200 lines, for me it is not object oriented programming. I am trying to ponder on the question and would ...
4
votes
2answers
11k views

Poker Hand Evaluator Challenge

This week's review challenge is a poker hand evaluator. I started by enumerating the possible hands: ...
2
votes
1answer
132 views

Performance issue with empty lists

Here's my updated version of the problem I posted at Calculating time windows for entities, adding in suggested changes as well as a change I did so that the Reflection is 'cached' in a ...
11
votes
1answer
526 views

C++ linq-like library

I want to implement something like C# Linq in C++ Currently only select and where is implemented, but others should be fairly ...
10
votes
4answers
5k views

Split IEnumerable by predicate

In order to divide an IEnumerable in C# by a predicate, I implemented the following (in a static class): ...
9
votes
5answers
951 views

Update grid from source hierarchy

In this question I answered with this Linq. While it does what I was looking for, I am not sure how easy the linq queries are for others to follow. So I am looking for feedback on formating, what ...
7
votes
3answers
258 views

Enumerating new articles whose publication start date has passed

(cn.PublishEnd == null || cn.PublishEnd < DateTime.Now) vs (cn.PublishEnd ?? DateTime.MinValue < DateTime.Now) Which ...
6
votes
1answer
779 views

IQueryable Extensions working on expression for collection property

Followup to Repository searching code duplication My goal currently is to make the current implementation of my repository's IQueryable filtering less duplicative. First, I looked into passing ...
5
votes
2answers
163 views

LINQish command line parser

I needed to parse some command line switches from a string and I tried to do it the easy way so I just wrote this: ...
5
votes
1answer
2k 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 ...
5
votes
1answer
126 views

Categorize episode-file names - Follow up

This is a follow up to this question. I have implemented changes to the code as they were suggested in the previous question and have made a few changes of my own. But it has been mentioned that the ...
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 ...
4
votes
3answers
3k views

Is ToIEnumerable<T> good practice?

I have an extension method that does this: ...
3
votes
2answers
2k views

Group list into elements with same value

This is my Result class: ...
3
votes
4answers
4k views

Alternative way to extract the most recent file using LINQ

All, I have written some code to get the latest files from a directory, the files I am looking for contain the string sProcScript = "sProcScript" and in the ...