Language INtegrated Query (LINQ) is a Microsoft .NET Framework component that adds native data querying capabilities to .NET languages.
0
votes
1answer
70 views
2
votes
1answer
49 views
Simplifying a LINQ expression that finds the largest date smaller than another date
I have a LINQ 2 SQL query that needs to run a subquery in the where clause. The subquery just returns the largest date (from a date column) that is less than or equal to another date (an input to the ...
3
votes
3answers
112 views
Enumerate list with filter criteria
Given the following CreditCard object, how would you get a count of unexpired credit cards? What are the pros/cons of using each method? Or is there a ...
5
votes
3answers
160 views
Sorting a list based on date and time
I have a class that is used to basically store samples from data being read from a system. Within that class is a property that I use to store the date and time of that sample:
...
8
votes
3answers
631 views
LINQ queries improvement - repetition of query
I have a DAL class full of LINQ queries which I would like to improve as I found that I'm repeating myself couple of times.
As you can see the part below is repeated couple of times and I was ...
-4
votes
1answer
32 views
Linq to get records of various status [closed]
I converted an Stored Procedure into a Linq Query, but it do not get any records.
Stored Procedure:
...
7
votes
3answers
183 views
Fetching a set of event IDs from a database based on a set of company IDs
The following code fetches a set of company IDs from a database if there are any events associated with a company that has a missing property. Because the set of company IDs is embedded into the SQL ...
3
votes
2answers
53 views
Find a serial port device through WMI (windows management instrumentation)
The idea here is to be able to find a USB serial port device connected during runtime, thus not knowing its port number, and use it in the application to retrieve information from the device.
...
3
votes
4answers
140 views
IEnumerable Extensions Linq AllOrDefault() Each()
I recently decided to try and write my own implementation of Linq, which then lead me on to trying to solve some of the problems we have in our code base at work. Our code is littered with the ...
2
votes
2answers
53 views
Linq-to-Sql Contains an int? inside a list of int
Curious if there is a better way to write a repository method that receives argument List<int> and checks if the database ...
2
votes
2answers
94 views
Checking for violation of primary key in a DataTable
I coded this function to check for a violation of a primary key in a DataTable. The main idea is to retrieve a list of every row that the same value of the column ...
2
votes
1answer
74 views
Counting email addresses with different status
I want to count email addresses with different status. I use ASP.NET MVC and this query is supposed to run every 5 minutes on these tables, which every table is on different .ndf files. About 5 ...
3
votes
0answers
70 views
12-week staffing forecast LINQ query
I have a LINQ query that I am having trouble optimizing and takes about 5.5 seconds to run. I am using a view called StaffingResourceData and a table called StaffingForecasts.
Each StaffingResource ...
2
votes
2answers
49 views
Grouping over a list of dictionaries
I am consuming data from an API that reads from a SharePoint list. The API is basically this:
...
-1
votes
3answers
60 views
Checking string length limitation and add items to it in a shorter way with Linq
This method has three parameters. If the extension is not null, for each item in list try to add extension to main text in a way that length of result doesn't exceed 20.
I wrote this code, but I ...
2
votes
1answer
61 views
Simplify my class mapping common class properties between model and viewmodel classes
I have an ASP.NET MVC 5 app and I map properties between model and viewmodel and vice versa.
I could use automapper to do this but since I don't need mapping rules to convince me to use it as I ...
2
votes
1answer
115 views
9
votes
2answers
86 views
IdentifierReferenceResolver: resolving at project level
One of the most important parts at the core of rubberduck is the IdentifierReferenceResolver class, which is responsible for resolving each declaration as the parse ...
1
vote
1answer
63 views
Deserializing multiple elements from XElement [closed]
I'm serializing multiple elements using this code:
...
3
votes
1answer
144 views
Using LINQ to perform a LEFT OUTER JOIN in 2 DataTables (Multiples criteria)
I know that exists a lot of solutions about how to create an OUTER JOIN between two DataTables.
I created the following code in ...
3
votes
1answer
48 views
Grouping two sets of data
The following method retrieves a list of users and the subscriptions for each user, from my database. That said, it works, but it runs pretty dang slow. I'd like to improve the speed on it. Currently, ...
0
votes
1answer
78 views
Getting prime numbers between a range
I have the following code to get the prime numbers between a range of numbers. Is this the best and fastest method?
...
1
vote
1answer
33 views
Retrieving a list, by iterating through a list
I'm using VB.Net, MVC 5, EF 6, and Linq. I have a list of Integers (category attribute IDs). I need to create a second list of ...
6
votes
1answer
84 views
Sum data that needs to be joined and grouped by
I have a list of patients, Patient class has Prescriptions property, which is a list of ...
7
votes
2answers
60 views
Convert an object to an ordered by SemVer Markdown list
For a small personal project, I am looking to convert an object to an ordered by SemVer Markdown list. You can find the original code for the sort logic here and here for the writing into Markdown ...
-3
votes
1answer
67 views
Which way is better (matching Onion Architecture in MVC pattern) for using Provider?
In onion arch. we have multi layer structre:
UI (User interface).
BL (Business Logic / Services).
RE (Repositories).
UI uses BL to get data from RE with some conditions, my question is which is ...
2
votes
1answer
74 views
LINQ filtering query
I often find myself writing LINQ queries like this. I end up testing for Null and zero-counts pretty often, and the code sprawls out to be something like the ...
5
votes
3answers
160 views
Filtering units by a dynamic Lambda expression
I have a simple if statement which, based on user input, determines which expression is going to be utilized. It looks like it can be done better.
...
5
votes
3answers
765 views
Convert Foreach Loop into Linq in C#
I want to convert these loops into simple loop. I want the code to look neat and short. I saw answers related to LINQ but couldn't make out from that. Are there any other possible ways for this ...
1
vote
0answers
85 views
Create JSON object from self-nested LINQ query
I created this function to created nested JSON object using a Linq query. How can I optimize this and make it more readable?
...
10
votes
3answers
112 views
FizzBuzz in accordance with standards
I wrote FizzBuzz. My aim is to use C# Code Standards correctly, and write flexible code. How can I improve my solution according to code standards? How can it be better in general?
...
3
votes
1answer
90 views
Storing user settings using LINQ to XML
I want to store some user settings into a file, so that the users get the same experience on all machines they're working on. The built-in user.config turned out to ...
4
votes
2answers
110 views
Commission calculation
I am trying to improve the performance of the current solution for calculating commission in a betting platform.
The following is the code currently used to solve the problem. The primary problem ...
-1
votes
1answer
137 views
Performance comparision of SQL queries versus LINQ in Visual Studio 2012
I am new to VS 2012 and need to use it with SQL Server. I need to get data from a table in SQL Server 2012 with 500 rows and 15 columns and process the data in it and update another table. All this ...
2
votes
1answer
75 views
LINQ queries to fetch first and last name
I have these two queries and they work just fine. I use the values they retrieve to populate a title for a view in my application. It seems though that I should be able to accomplish this with one ...
4
votes
1answer
118 views
Inserting customer care database analysis detail records
I have written this linq-to-sql query to insert a bunch of customer care database analysis detail records:
...
4
votes
3answers
412 views
Return IEnumerable<KeyValuePair> from a private method; use Dictionary or anon. type?
Is it okay to return IEnumerable<KeyValuePair<string, string>> from a private method instead of returning a read-only dictionary? This allows for ...
0
votes
1answer
80 views
Optimize LINQ search with custom fixed ranking
I have to perform on some collection and return ranking based on some logic
I wish to optimize this working code since I think it can be bettered (maybe using tasks?).
I need to search on ...
4
votes
1answer
95 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. ...
2
votes
1answer
74 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
63 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
86 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
150 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
92 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
1k 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
178 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
300 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
184 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
91 views
Linq refactoring
I have some code that asynchronously load some point in chart when user drag it.
...