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
3 votes
3 answers
116 views

Add multiple instances of a property to a list [closed]

I'm a novice programmer asking first question here although I've gotten tons of help from previous questions. The following code is abstracted from what I currently have working. ...
speedycorndog's user avatar
10 votes
4 answers
7k views

Split IEnumerable by predicate

In order to divide an IEnumerable in C# by a predicate, I implemented the following (in a static class): ...
Heman Gandhi's user avatar
2 votes
1 answer
351 views

Sort group item by attribute

I have a repository method which retrieve a list of items, for example: ...
invernomuto's user avatar
7 votes
1 answer
331 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: ...
Mathieu Guindon's user avatar
0 votes
1 answer
1k views

create generic method for two different anonymous types

Function 1: ...
SivaRajini's user avatar
3 votes
2 answers
604 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 ...
Dmitry Nogin's user avatar
  • 6,133
4 votes
1 answer
103 views

Loading and updating data from system A to system B

I need to transfer purchase order (PO) information from SQL Server into Sage 300 ERP, so using my Linq-to-Sage implementation, I wrote a little console application that connects to a SQL Server ...
Mathieu Guindon's user avatar
0 votes
1 answer
232 views

Is my LINQ query safe and efficient?

I am relatively new to LINQ queries as I normally just use plain SQL to get my data back but i am changing for the good - Anyway obviously with SQL you pass in parameters so you do not get any SQL ...
user avatar
2 votes
3 answers
2k views

Building XML elements from a list using LINQ and foreach

I wrote the following code: ...
Emaborsa's user avatar
  • 193
0 votes
1 answer
584 views

Count check before Linq Single() call

Should I check Count before Linq Single() call if I expect only one element? ...
SerG's user avatar
  • 171
11 votes
6 answers
7k views

PermMissingElem- find the missing element in a given permutation in C#

I just encountered this question in codility but apparently this question has been asked in java already (here, here). Task description A zero-indexed array A consisting of \$N\$ different integers ...
Tolani's user avatar
  • 2,471
5 votes
1 answer
378 views

Merging trips to the same location with overlapping dates

I have a SQLite database that only contains the holidays for 1 user. I have a new Trip object (newTrip) that has a ...
Percy's user avatar
  • 193
4 votes
1 answer
150 views

Retrieving collections from a database

I have two collections that I want to retrieve from the database and associate with each other. My solution works, however I know it isn't the most elegant one. Do you have any suggestions on how to ...
Michael Vakoč's user avatar
12 votes
1 answer
12k views

Find the odd occurrences in an array

Recently, I came across this problem on Codility. I am aware there is a bit of similarity to this question and this question, but I am trying to achieve this in C#. The problem is as follows: A ...
Tolani's user avatar
  • 2,471
1 vote
1 answer
842 views

Conditional aggregate whilst constructing array

I have the following snippet of code which gets a load of time intervals (every hour, every 2 hours etc), then groups the results for each of the intervals (e.g, the max value for each hour). This ...
ETFairfax's user avatar
  • 135
0 votes
1 answer
51 views

disable other default row- Entity framework

I have a table that name is Store , In Store Table , just one row can IsDefault=true at ...
Uthman Rahimi's user avatar
0 votes
1 answer
8k views

Map a hierarchy of nested DTO objects to a list of business objects [closed]

Consider I download my data into this data structures: ...
user avatar
4 votes
2 answers
197 views

Stitching Linq with if blocks

I recently learned about Linq's deferred execution and a little clearer understanding of IEnumerable. I came back to some code that I had written and decided to change with Linq extension methods. (...
LockeGarmin's user avatar
3 votes
1 answer
166 views

Rolling up Invoice Items Matching Certain Criteria

I have a listing of invoice line items that I need to apply some convoluted business logic to. We have another listing of items that I compare the invoice items to and if I find matches, I then need ...
Michael McGriff's user avatar
1 vote
2 answers
105 views

Find items in collection one that are the greatest value less than an item in collection two

This is hard to explain. I wanted to get all of the items in collection one (ints in the example below) that are the highest values that are lower than any of the items in collection two (otherInts). ...
sonicblis's user avatar
  • 203
3 votes
2 answers
5k views

Customer search using LINQ followed by conditional filtering of results

I have a search function in my class which checks various class property values for null or certain values and queries the database based on those properties. This how my function looks like now: <...
JustLearning's user avatar
2 votes
1 answer
134 views

Getting price for one firm by week

I've a lot of data whit prices of a product from different firms by week. I've a class named WeekPrice witch contains a list of ...
H. Pauwelyn's user avatar
0 votes
1 answer
253 views

Skip by Id on large list

This is in ASP.NET MVC, but that shouldn't make a difference. I have a large number of rows in my database for Songs. ...
Martin Dawson's user avatar
3 votes
2 answers
303 views

Operator-based switch for a database query filter

I am currently working on a method, that can search based on a value and an operator. Currently I check which operator was supplied to the the method in a switch, and do operations accordingly to it. ...
user avatar
1 vote
1 answer
20k views

Passing model to _layout.cshtml

I have login page that looks like: It has a ViewModelBase and a ViewModel as: ...
niklodeon's user avatar
  • 193
5 votes
3 answers
198 views

OnStartApplicationsCommand function

The foreach loop seems ridiculously lengthy and I am trying to get rid of it altogether is possible. But there are a lot of things happening in there which I need ...
meonstackexchange's user avatar
1 vote
1 answer
293 views

Efficiently update string (in XML format) in MongoDb

...
Anatoly's user avatar
  • 286
2 votes
1 answer
5k views

Distinct List of attribute values from XML, using a pre-defined set of attribute names

I have an XML stream that looks like the following (attribute and node quantity , and node depth reduced for demonstration purposes.) ...
ThunderFrame's user avatar
  • 1,969
1 vote
1 answer
100 views

LINQ query for a user's submitted time-off requests

What is a better way to create this select statement? I tried to just select 'u' and 'us', but the object properties were not accessible when I did this. ...
jon.r's user avatar
  • 409
10 votes
1 answer
33k views

Using Linq instead of multiple foreach loops

A project I'm working on often has lists within lists within lists etc. The original author often uses complicated linq expressions, but when adapting them I mostly get hopelessly bogged down and ...
BMills's user avatar
  • 231
10 votes
3 answers
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: ...
Mathieu Guindon's user avatar
2 votes
1 answer
2k views

Building expression tree with multiple OrElse

I am creating a way for users to filter results based on start and end values. An example of this would be: ...
GBreen12's user avatar
  • 121
5 votes
1 answer
213 views

Paginating blog posts from SQL server using nested LINQ statements

I made an ASP.NET MVC application using Entity Framework for code-first migrations to the SQL Server database. I also use Unity (DI/IoC) for managing the services and repositories. I made an overview ...
H. Pauwelyn's user avatar
0 votes
1 answer
2k views

Method or helper function to return objects from EntityFramework with Linq [closed]

The following code reads from Microsoft EntityFramework 6.0 domain model and returns the single view_patient object. The view_patient object is defined in the backend database and uploaded to the ....
Alan Wayne's user avatar
2 votes
1 answer
3k views

Converting from strings to byte arrays with LINQ in C#

I'm taking in a string of input from the command line, and when prefixed by 0o or 8# interpreting it as an octal string. I'd ...
Ehryk's user avatar
  • 123
7 votes
2 answers
2k views

Struct implementation of immutable Maybe<T> monad

I have developed the following implementation of an immutable struct Maybe<T> monad for use in my game project; as an ...
Pieter Geerkens's user avatar
4 votes
1 answer
12k views

Convert reader to list of class

Class Student { Int studentId, List<ClassB> Books, Bool IsPassed } Class Book { Int bookId, List<int> pages } I am creating a list ...
Silly Volley's user avatar
1 vote
1 answer
487 views

Eager Loading Deeply into a Model with a Collection Property Whose Type is Inherited

Visual Studio generated this great route for me, where I can load an entity: ...
Scotty H's user avatar
  • 133
2 votes
2 answers
101 views

How to find contradiction in order of items in multiple sequences

Suppose you have several sequences: A: 1 2 3 4 5 B: 2 4 5 C: 2 1 3 4 5 D: 3 2 Here, some pairs of list contradicts each other, because they ...
Ahmad's user avatar
  • 141
10 votes
1 answer
260 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... ...
Mathieu Guindon's user avatar
3 votes
1 answer
2k views

LINQ statements that aggregate sums from a List of objects

I'm packaging data for use in a JavaScript charting library that expects a somewhat odd structure of data in which there is an array of labels and an array of ...
sonicblis's user avatar
  • 203
2 votes
2 answers
320 views

Medical appointment book history

This code correctly returns a View_appointment. Is there a better way to accomplish this with using left joins and unions? I'm trying to learn Linq a little bit ...
Alan Wayne's user avatar
0 votes
1 answer
64 views

Pull back records that include child records

I am trying to pull back records that include child records for the View I'm putting together. Right now I have a working Linq statement, but it's big, and I think I could make it cleaner. ...
Mark Kenyon's user avatar
5 votes
1 answer
134 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 ...
Paras's user avatar
  • 585
3 votes
2 answers
668 views

Convex envelope algorithm of random set of points

This is my "naive" implementation of a convex hull algorithm. By naive I mean that I am not using any of the advanced algorithms that exist to solve this problem. ...
InBetween's user avatar
  • 649
11 votes
3 answers
845 views

Give me thy name, I'll invoke thee

This generic function invokes a property of a given object by name: ...
user avatar
5 votes
1 answer
505 views

Using LINQ to output SQL data from two tables into XML

I am very new to this. Hope someone could help me suggest how to improve the code. I have two tables where I need to get the SQL data and output it into XML format. I am using LINQ method. Below how ...
C Python's user avatar
6 votes
1 answer
5k views

Joining datatables to create a new datatable

I am joining datatables to create a new datatable: ...
Harshit's user avatar
  • 183
12 votes
2 answers
7k views

Query Builder pattern with use of FluentApi

Recently, I've come up with an idea of building a custom query builder combine with FluentApi. Expected usage: ...
Kien Chu's user avatar
  • 231
-5 votes
2 answers
5k views

Remove from list value where date less than max date value

How can I improve this code? ...
Roman Marusyk's user avatar

1
3 4
5
6 7
13