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
1 vote
1 answer
5k views

Selecting employees in certain departments using LINQ

I am trying to select the DepartmentName from Employee Table based on where condition. Is any way to simplify the code? ...
Vignesh's user avatar
  • 129
1 vote
1 answer
12k views

Linq group by with multiple where, sum clauses in select causes a timeout

I have linq query that extracts a summary of my sales quantities item group wise. This query causes an sql ...
JustLearning's user avatar
2 votes
0 answers
311 views

Entity Join slow query

I've never participated in a codereview before and I was pointed that I should in another thread for a slow query. ...
Cowmoogun's user avatar
  • 129
-1 votes
1 answer
327 views

Test helper method to assert if text could be found

Lately I've been getting a lot of critique in my code reviews at work, where typical comments have been that my variable names are unclear/confusing, flow in method could be simplified, unnecessary ...
Force444's user avatar
  • 243
3 votes
2 answers
2k views

Copy an Entity With Navigation Property in C#

I have a table named Asset and each Asset has schedules. I create a method like this for copying an entity: ...
work question's user avatar
5 votes
3 answers
8k views

Concise code to perform action on every element, when need index

When I read this answer, which has code: ...
ToolmakerSteve's user avatar
2 votes
2 answers
855 views

Get first DateTime by given weekdays and a starttime

At work there is an input-system where customers are able to specify weekdays and a starting time for an event. The weekdays are integers in the range from 1 (Monday) to 7 (Sunday). After the customer ...
nonsensation's user avatar
0 votes
1 answer
219 views

Filtering data on basis of attribute values

I am writing code to filter data on basis of attribute values. It is possible that the user can select multiple values. How can this be better? ...
Raman Kumar's user avatar
4 votes
3 answers
12k views

Splitting a list of numbers into multiple lists

I need split the list I get from the select into multiple list so I can use Parallel.For() to generate the next query in different threads. I create the main list ...
Juan Carlos Oropeza's user avatar
0 votes
1 answer
5k views

Multiple enumerations of IEnumerable

I have a snippet of code here that uses C# and Linq. The ganttData variable I have has 12 warnings stating: possible multiple enumerations of IENumerable Should ...
Train's user avatar
  • 301
0 votes
0 answers
238 views

Join via navigation properties with collection

There are some related collection objects in my table and I'm trying to get list with joining this tables. But this code is seems bad: Entities that shortened: User: ...
Tugrul Emre Atalay's user avatar
2 votes
1 answer
310 views

LinQ wrapper to get distinct items from a IEnumerable based on a function of item

I often need to perform LinQ queries to get distinct items from a IEnumerable based on one of its properties. I would like to know if this is a good way to wrap this operation: ...
VBobCat's user avatar
  • 307
2 votes
2 answers
65 views

Locating people by roleId

Basically, I'm trying to find all active people with a roleId of 3 (analyst id). But I want to exclude ids that were created as test analysts, i.e. "130", "252", ...
inquisitive_one's user avatar
5 votes
1 answer
213 views

Linq-like functions in JavaScript

Today was my first day working with JavaScript and I tried to implement some Linq-like (C#) functions as extension methods. I'm pretty new to JavaScript and wanted to ask you for checking my ...
Matthias Burger's user avatar
-2 votes
1 answer
1k views

Linq query combining three tables [closed]

I have a linq query that combines three tables: Users, Products, and User_Has_Products I ...
Aaron's user avatar
  • 943
2 votes
1 answer
7k views

IQueryable left outer join linq extension

I wanted to create an extension method to enable left outer joins in linq/lambda IQueryables, and I have come up with the following, but I am still not sure it's completely correct. ...
Kravaros's user avatar
  • 129
2 votes
2 answers
235 views

Updating database based on selected check boxes

I posted the original question here, but I think it would be nice to have someone else's eye on this code for improving it. ...
Sirwan Afifi's user avatar
5 votes
2 answers
395 views

Constructing file paths for each row of a datatable in C#

I need to iterate through a DataTable and columns in each rows and do some data manipulation. Below given is an extract from my code, I use c#.net. I expect maximum rows in datatable will be less ...
blue's user avatar
  • 171
6 votes
2 answers
17k views

Get XML elements with a particular attribute value

I have the following code to find xml elements that have a particular attribute value: ...
pushkin's user avatar
  • 289
9 votes
6 answers
10k views

LINQ to SQL query filter, with the name match ignoring multiple punctuation characters

I have the following LINQ to SQL query which works fine but looks ugly: ...
dochoffiday's user avatar
8 votes
2 answers
732 views

Grouping reviews by UserId

The class I'm using is called Review and looks like this: ...
RandomStranger's user avatar
5 votes
1 answer
914 views

Climbing the stairs

A quick description on the problem I solved on codewars.com but remember I just want a small part of my solution refactored (just the for-loop): Description ...
Gringo Jaimes's user avatar
4 votes
3 answers
5k views

Sort and merge list based on another list

Here I'm merging a list to end of another list after sorting it according to another list.This should sort processdetails list according to the order in routeplans list if any item not present in ...
Manioth Shijith's user avatar
2 votes
4 answers
10k views

Check if the user exists

Scenario: Check if the user exists If yes: update the details Else: insert the user details ...
Kgn-web's user avatar
  • 161
7 votes
4 answers
468 views

Using LINQ to group social networking links for each user

I have a model named User. Each user can have some social links. Now I want to get all users with their social link as a single row in the result. Here are my ...
Sirwan Afifi's user avatar
11 votes
4 answers
2k views

Country code lookup for each line in a CSV file

I'm trying to write a program that has a for loop, inside of which I have lambda expression to get a certain value. The loop has about 20,000 iterations. Including ...
psyoptica's user avatar
  • 121
4 votes
2 answers
223 views

Transform a List of objects to a string of unique values for use in an SQL query

I have a List of Results. My goal is to extract the Result property ...
Tomas Paul's user avatar
5 votes
3 answers
3k views

HackerRank woman codesprint: minimum cost

Lauren has a chart of projected prices for a house over the next n years, where the price of the house in the i-th year is <...
Jianmin Chen's user avatar
  • 2,396
6 votes
1 answer
1k 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 ...
Chris Thompson's user avatar
4 votes
2 answers
272 views

Migrating data using entity framework, linq and recursion

I have a piece of code to migrate data from an old app to a new app. The data represents the user's websites. In the old app the user only had one section for websites, on which you could add any ...
Dimitri's user avatar
  • 221
4 votes
1 answer
2k views

Retrieving website categories from a three-level hierarchy

I've been trying to fix this performance bottleneck in my web app for a while now. Here is what the data looks like on my web page: Here is how I get this data in the controller: ...
nmit026's user avatar
  • 141
2 votes
1 answer
1k views

Unfold a 2D array spiral in C#

The purpose of this function is to turn a 2D array of sorts into a single-dimensional array by reading it in a spiral fashion. In the array: 1 2 3 4 5 6 7 8 9 ...
downrep_nation's user avatar
4 votes
3 answers
796 views

Pangrams implementation using Linq

This is a continuation of my LINQ stories from Pangrams-Hackerrank. Similarly, this challenge has been asked before in python Pangrams python Implementation but I have tried to accomplish this ...
Tolani's user avatar
  • 2,473
4 votes
2 answers
4k views

Diagonal difference using Linq

Recently, I have been trying my hands on LINQ. So I've implemented the diagonal difference using Linq in Hackerrank. I know a similar question has been asked in python Diagonal Difference Here is an ...
Tolani's user avatar
  • 2,473
3 votes
2 answers
504 views

Implementing SOLID Principles - LINQ TO SQL

I have been using Layered Architecture in my web application. Can anyone please advise if my data layer classes (both Linq and booking class) can be improved? I have just started learning about solid ...
Umar's user avatar
  • 131
5 votes
2 answers
1k views

Chunking a list into separate lists of 5, and then iterating through each

I'm writing a service that receives a list of Latitude/Longitude objects, prepares them for transaction, and then calls a web service to write them to the organization's Mainframe. According to the ...
alaskanloops's user avatar
1 vote
2 answers
534 views

Filtering data for jQuery DataTables

Using DataTables (Table plug-in for jQuery) with server-side processing, I had to create filtering for my data with good performance. However, in my opinion it's kinda ugly, especially the part of (<...
DiPix's user avatar
  • 111
10 votes
6 answers
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 ...
Malachi's user avatar
  • 28.6k
2 votes
2 answers
364 views

Creating monthly files from an annual file

I am interested in learning a more succinct (or better performing) way of writing the following working code. I just figured it out but it is pretty messy. This program takes a file full of daily ...
MattyMc's user avatar
  • 33
4 votes
1 answer
599 views

Delete records from multiple tables when deleting a subproject [closed]

In my program I am deleting subprojects using LINQ. It's incredibly slow. There is a lot of cascade on delete's here so I am deleting from multiple tables. Any help and tips would be appreciated. ...
Train's user avatar
  • 301
4 votes
3 answers
7k 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 ...
AED's user avatar
  • 197
1 vote
2 answers
121 views

Reading in a file and ranking result to output file

I am reading in a file which consists of scores between two teams. The team that wins gets 2 points, if the teams tie both teams get one point. The result is ranked by points and if there is a tie ...
Aaron's user avatar
  • 943
4 votes
3 answers
656 views

Concatenating two IEnumerables with a limit

I've been playing around with generators, generics and extension methods in C# (5.0) and wanted to create an extension method for IEnumerable, which would append ...
overactor's user avatar
  • 654
2 votes
2 answers
3k views

Creating a random code and saving if it does not exist

I have created a script to generate 5 random codes, check if any one of them exists in the database, and if not, insert the record. The script will throw an exception if a single code could not be ...
user1477388's user avatar
2 votes
1 answer
2k views

Simple generic linq expression generation method

Here is my generic method for creating linq expression based on field name of a type, operator (as enumerations of operators generated from XSD) and value of field ...
Anton's user avatar
  • 267
0 votes
2 answers
2k views

LINQ sorting using custom IComparer is very slow

Joining a project with some crazy LINQ sorting statements and after refactoring by the team using a custom comparer we found out that it is so slow for some data that you actually think it is an ...
xplat's user avatar
  • 177
5 votes
2 answers
184 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: ...
t3chb0t's user avatar
  • 44.1k
4 votes
2 answers
3k views

Search for variants of keywords using LINQ

First, I'm adding words entered into a search field to an array. Then, I'm getting results from a stored procedure on SQL Server using Database First approach with Entity Framework. Finally, for ...
thetipsyhacker's user avatar
8 votes
1 answer
543 views

Linqy Sudoku game generator

I created a class that is able to generate a Sudoku board. The following board generation steps are made: Create a valid board with numbers on all squares, row by row Basically I always generate ...
Bruno Costa's user avatar
  • 5,566
2 votes
2 answers
25k views

Check if an Array of Arrays contains a value in node js

In C#, I could check if any of the nested List collection has a value. Example of such structure Check a List[]> contains a value using Linq ...
Tolani's user avatar
  • 2,473

1 2 3
4
5
13