Questions tagged [linq]
Language Integrated Query (LINQ) is a Microsoft .NET Framework component that adds native data querying capabilities to .NET languages, although ports exist for Java, PHP, JavaScript and ActionScript.
89
questions
3
votes
4
answers
419
views
Sorting a sequence according to a hierarchical set of rules
We are producing configuration files for a production system.
The configuration files have a dynamic set of variables. Optional values and other values that only need to exist based on other values.
...
1
vote
1
answer
180
views
Distribution of processing across cores between a LINQ and PLINQ query
I am trying to create a simple demonstration of using 'parallel LINQ' (PLINQ). I have two versions of my task, in C#:
var result = Enumerable.Range(1,1000000).Where(x => IsPrime(x)).ToList();
...
-1
votes
2
answers
416
views
What makes LINQ (C#) unique compared to another DSL such as Django query syntax?
My question to the community is this:
What makes C#'s LINQ Unique from other query language in other languages and frameworks, or does it not have anything to make it unique at this point?
...
1
vote
3
answers
5k
views
Need help finding an efficient way to group the keys in a dictionary into buckets defined by the values in the dictionary?
I have a dictionary in the form of Dictionary<int, List<int>>
The problem is that I need to group the keys together into buckets defined by the value (List<int>). It is easier to ...
1
vote
1
answer
52
views
Finding Event-Oriented Patterns in temporal sequence
I have a 24 hour "sliding window" sequence of "start" and "stop" events in memory comming from an iOT device.
I'm only interrested in finding "stop" events followed by "start" events in order to ...
5
votes
1
answer
662
views
Are legacy C# DataTable/SqlDataAdapters exponentially faster than SqlConnection/SqlCommand and/or LINQ to SQL DataContext.ExecuteCommand calls? [closed]
I can't believe DataTable/SqlDataAdapter massively beat out System.Data.Linq.DataContext.ExecuteCommand and ExecuteNonQuery (tried with both Stored Procedures and command text) and just straight ...
0
votes
0
answers
186
views
Tradeoffs between Testability and Performance when filtering using SQL vs LINQ
My team has recently decided to adopt the CQRS pattern similar to the one used in the famous Microsoft EShopsOnContainers repository. In this solution, the queries are made in Query classes using ...
0
votes
0
answers
2k
views
.NET WPF Best way to store a connection credential
I have an application that connects to SQL Server using windows credentials, which works very well for the domain paradigm. The client is now transitioning away from having a domain server, and is ...
2
votes
0
answers
65
views
How to join two sets of 6 tables and select the list into another set of 6 tables
A1
|__A2
|__A3
|__A4
|__A5
B1
|__B2
|__B3
|__B4
|__B5
C1
|__C2
|__C3
|__C4
|__C5
Given a list of A and a list of B, we want to "join" ...
6
votes
4
answers
2k
views
Replacing Linq Methods with Extension Methods
So, I've fallen into the fad trap, and started replacing a large amount of linq queries with extension methods.
For example:
orders.Where(o => o.Status == ShippedStatus.Shipped).Select(o => o....
43
votes
13
answers
29k
views
Is it unreasonable to expect Any() *not* to throw a null reference exception?
When you create an extension method you can, of course, call it on null.But, unlike an instance method call, calling it on null doesn't have to throw a NullReferenceException -> you have to check and ...
1
vote
1
answer
275
views
Which is best software design for heavy query based app
I am in charge of design an application (.NET) that has these features:
It´s a desktop app (maybe in the future will be web-based)
It´s functionality is to provide users analyzed data retrieved ...
20
votes
6
answers
4k
views
What advantage was gained by implementing LINQ in a way that does not cache the results?
This is a known pitfall for people who are getting their feet wet using LINQ:
public class Program
{
public static void Main()
{
IEnumerable<Record> originalCollection = ...
0
votes
1
answer
270
views
Reactive Programming in C# - how to roll my own?
I've been using Linq for a while unknowingly that it uses a Reactive pattern that I'm quite fond of.
I'd like to roll my own function in that pattern but wasn't sure if it's appropriate and also ...
2
votes
4
answers
212k
views
Null or empty object when LINQ to Entities query returns nothing
Say I have a LINQ query like this:
application = CreditDatabase
.Applications
.Select(Mapper.Map<Application>)
.Where(c =...
18
votes
1
answer
3k
views
Unit tests: deferred assertions with Linq
Is it ok to add deferred assertions like this
var actualKittens = actualKittens.Select(kitten => {
Assert.IsСute(kitten);
return kitten
});
Why? So I can iterate just once even with ...
1
vote
2
answers
7k
views
How do you create a Linq IQueryable Where query with string predicate and params object[] arguments
I would like to create a IQueryable Where method as shown below:
public static IQueryable Where(this IQueryable source, string predicate, params object[] values)
{}
So instead of Where(u => u....
4
votes
5
answers
9k
views
Import large csv files
I've been tasked to query 2 large csv files which are roughly 1 GB in size each. The files contain related data, so file one may contain a list of order numbers, Order Dates, etc and the file may ...
4
votes
2
answers
264
views
Name for a Chainable ForEach [closed]
Linq has a method Select, which takes a Func<TIn, TOut> and maps it over an iterable.
I'm trying to come up with a good name for a method that takes an Action <TIn>, transforms it to ...
22
votes
3
answers
3k
views
What is the reasoning behind naming of the .NETs Select (Map) and Aggregate (Reduce)?
In other programming languages, I have seen Map and Reduce, and those are cornerstones of functional programming. I could not find any reasoning or history why LINQ has Aggregate (same as Reduce) and ...
0
votes
1
answer
3k
views
Efficient way in comparing two lists
I have created two lists of objects: One is records from an xml and the other is records from the database.
The rule is check if the record from an xml exist in the database then exclude.
I have ...
0
votes
1
answer
917
views
Create an item in two different table with auto-increment C# SQL [closed]
First of all, let me apologize because I know my question will be very confusing since my English is pretty bad.
I am working on a project for a company, mainly create a system to take care for ...
4
votes
3
answers
328
views
How to avoid the LoadBy pattern?
In our codebase for a sophisticated system controlling many aspects of businesses, we have a certain unwritten law to not fudge around in code with complicated SQL, instead writing it into a function ...
0
votes
2
answers
8k
views
how to do temporary tables in Linq to Entity Framework
Our application queries the database primarily using Linq queries backed by Entity Framework but we sometimes call legacy stored procedures. Sometimes we want to replace an existing stored procedure ...
6
votes
1
answer
2k
views
The best way to convert Dynamic SQL to C#/Linq while joining multiple tables
I am trying to find the best way to convert the following dynamic SQL snippet to C# / Linq. The question is complicated by the use of multiple tables within the dynamic SQL.
I've examined the ...
6
votes
1
answer
5k
views
Should I write complex Linq queries?
I often find complex Linq queries that span over 10-15 lines in our code base.
I find such queries hard to understand and impossible to debug.
I've tried to split the query to smaller parts, but it's ...
0
votes
1
answer
1k
views
C# Constructor and private LINQ to SQL members
I am extending an application I have developed so that it is more broadly useful for multiple jobs, rather than the single job I created it for. There are a number of tables that I get from SQL ...
0
votes
1
answer
10k
views
Most efficient LINQ result for Contains() query
I currently use the following:
var result = list.Union(otherList).SelectMany(l => l.children).ToList()
foreach(var child in lotsOfChildren){
something = result.Contains(child)
}
I only use ...
1
vote
1
answer
1k
views
Portable Data in C# App
I have developed a C# front end app for management of an SQL Database for the purposes of document control. The project this database is for has several consultants and a client spread in a variety ...
3
votes
1
answer
5k
views
How to write unit tests for a piece of code that has a data context?
I am new to unit testing and using Microsoft's unit testing library for following piece of code. When I execute the code normally it executes fine, however when I run unit test written for this code I ...
0
votes
1
answer
1k
views
Good design pattern for linq to sql
I currently have a linq to sql project that was used for one project and not much work was put into it, only the generated context and entities were used. Since then the project has started to become ...
0
votes
1
answer
694
views
More appropriate to validate a dependency filter parameter by mock+stub or by expression compile?
My lead is enforcing TDD on our project. He says he's following Uncle Bob (Robert Martin) and SOLID principles. One of the rules he's reinforcing is what I call "the single cog rule"--there should be ...
2
votes
1
answer
4k
views
Why does Linq to Entity Sum return null when the result set is empty?
There are quite a few questions on Stack Overflow about the Linq to Entity / Linq to SQL Sum extension method, about how it returns null when the result set is empty: 1, 2, 3, 4, 5, 6, 7, and many ...
7
votes
1
answer
7k
views
There's a most performant way to check that a collection has exactly 1 element?
I came up with this solution :
if (Take(2).Count() == 1)
is there any more performance solution (or better syntactical sugar) to do this check ?
I want a performance way because this will be an ...
1
vote
2
answers
2k
views
Is it faster to query using linq-to-entities or a data adapter?
I'm creating an MVC application in VS2012 and I reverse-engineered the models from existing Oracle tables. The tables are part of a MASSIVE database. Besides the main tables that I need to insert, ...
0
votes
1
answer
1k
views
Simplifying data search using .NET
An example on the asp.net site has an example of using Linq to create a search feature on a Music album site using MVC. The code looks like this -
public ActionResult Index(string movieGenre, string ...
2
votes
2
answers
128k
views
foreach in list or foreach in list.where [duplicate]
I don't know what to call this question.
This is my example:
foreach (var item in lstItem.Where(item => stock.ItemCode == item.ItemCode))
{
stock.ItemName = item.ItemName;
stock....
0
votes
1
answer
238
views
Preference to see if a field's value was changed js or linq object?
We have some requirements to send emails when various field values are changed in our system.
It's an asp.net system using linq to sql with javascript/jquery.
Is it preferred to check if a value ...
1
vote
2
answers
1k
views
TDD - Making assertions about C# Expression trees
How would you unit test the PerformUpdate method in the sample below? This is a (very) simplified version of some code that performs updates against a database where the schema is dynamic and ...
2
votes
3
answers
3k
views
Optimal way to implement this specific lookup table in C#?
I want to create a lookup table for this data:
The "input variables" (what is used to "lookup") are 4 different doubles that can each take on 1 of 200 numbers (the numbers range from 1-1000 but there ...
5
votes
1
answer
5k
views
which sorting algorithms is using OrderBy
I am litle curious about what sorting algorithm is using OrderBy (linq to objects). quicksort? heapsort? introspective sort ?
As i see in MSDN documentation List.Sort is using introspective sort:
...
0
votes
1
answer
481
views
C# LinqExtensions implement multiple inheritance
According to WikiPedia
"Some languages do not support mixins on the language level, but can easily mimic them by copying methods from one object to another at runtime, thereby "borrowing" the mixin's ...
6
votes
4
answers
7k
views
Is it possible to implement an infinite IEnumerable without using yield with only C# code?
Motivation
The main idea is to explore and understand the limits of how far one can go with the basic LINQ primitives (Select, SelectMany, Concat, etc.). These primitives can all be considered ...
13
votes
4
answers
3k
views
Is linq more efficient than it appears on the surface?
If I write something like this:
var things = mythings
.Where(x => x.IsSomeValue)
.Where(y => y.IsSomeOtherValue)
Is this the same as:
var results1 = new List<Thing>();
foreach(...
3
votes
1
answer
2k
views
Using Dynamic LINQ to get a filter for my Web API
We are considering using the Dynamic.CS linq-sample included in the "Samples" directory of visual studio 2008 for our WebAPI project to allow clients to query our data.
The interface would be ...
3
votes
2
answers
4k
views
Extracting lambda expressions from linq queries and readability
Every now and then when I have a complex lambda, I do something like this:
Func<SomeObject, bool> equals = o =>
o.ID == someID && o.Name == someName && IsAdd || ...
var ...
17
votes
5
answers
22k
views
XSLT and possible alternatives [closed]
I had a look at XSLT for transforming one XML file into another one (HTML, etc.). Now while I see that there are benefits to XSLT (being a standardized and used tool) I am reluctant for a couple of ...
2
votes
4
answers
612
views
Why should IQueryProvider implementations throw NotSupportedExceptions?
Searching the web, we can find plentiful examples of various ORMs (nHibernate, EF, LinqToSql, etc.) that implement but don't actually support the full IQueryable<T> interface, throwing ...
13
votes
1
answer
16k
views
Why is imperative programming preferred over functional programming? [closed]
Background: I am proponent of functional programming who works at a VB.NET shop where the prevailing mental model is imperative programming. Being that foundation of our system is WinForms I can ...
3
votes
1
answer
920
views
Is it okay to convert dataset from stored procedure to IEnumerable
So, I am working on a project with a team and we are using Entity Framework. We basically want to use linq to entities, and not use stored procedures. I use quite a bit of lists and IEnumerables and ...