Questions tagged [linq-to-objects]
The term "LINQ to Objects" refers to the use of LINQ queries with any IEnumerable or IEnumerable<T> collection directly, without the use of an intermediate LINQ provider or API such as LINQ to SQL or LINQ to XML.
1,358
questions
0
votes
0
answers
23
views
Order of invocation of LINQ functors
Lets assume i call a LINQ function like Select, or Where, or Distinct, etc. on a Lits<T>, array, or another 'standard'IEnumerable<T>. Are there any requirements, guarantees, or lack ...
1
vote
1
answer
210
views
Get list of matching objects from 3 different lists
I'm exercising on one task. Basically i got 3 different lists in C# code side. Class employee is containing the skills list. And also have list of employees as well.
for example :
class Employee
{
...
0
votes
1
answer
800
views
Return a single object from a list of C# objects checking for matching properties
I have a requirement to create an object 'factory' that works as follows:
Accepts a list of matching object types.
Compares each property value in the list to see if they match.
Returns a new single ...
0
votes
2
answers
166
views
Linq - Join collection with child collection of other collection
I have a collection of users, each with a child collection of memberships. And then I also have a club collection. The child collection of each user is populated with memberships containing a club ID ...
0
votes
2
answers
292
views
LINQ for equivalent for-loop on multi-level nested collection, extracting index information
I have an instance variable _foo declared like so -
List< Dictionary<int, HashSet<int> > > _foo;
Yes, it is a messy data structure that is a List of Dictionaries whose key is an ...
1
vote
1
answer
114
views
C# grouped objects aren't being mutated as expected
I have a collection of objects entering a method as an IEnumerable of which I am grouping them by a reference property and then processing them group by group. The processing involves mutating the ...
0
votes
2
answers
185
views
LINQ to Object - How to implement WHERE clause `If at least one of the elements is` for sub-group
I have a type of non-ordered records:
public class Row {
public string Client { get; set; }
public string Account { get; set; }
public string Status { get; set; }
}
and its instantiation ...
0
votes
0
answers
55
views
merge multilevel json object to create stagged object with no loss of data
I want to merge two multi-level object to form a single object with no loss of data.
till the level data is same no extra fields should be added, at level where fields are different new object should ...
1
vote
2
answers
53
views
How to LINQ DataTable with group by and order by to deduplicate data
I have the following datatable
Col1
Col2
Col3
A
B
1
A
B
2
A
C
1
The Col1 and Col2 is the unique key so the first and the second row is duplicated.
The Col3 differ so I would like to have an ...
0
votes
2
answers
201
views
LINQ to Object - How to implement dynamic SELECT projection of sub elements
I have several classes of business logic:
public class Client {
public string Code { get; set; } = string.Empty;
public string Status { get; set; } = string.Empty;
public string Account { ...
0
votes
1
answer
394
views
Optimize the slow query in-memory List using LINQ for retrieving data
I have a LINQ query that I am having trouble optimizing. It takes about 6 seconds to run.
IList<Note> notes;
data = client.Configuration.Data.OfType<UWData>()
.Where(s => s....
0
votes
2
answers
74
views
LINQ to get array of newest items in array
I have a list with objects such as this one:
public class ReportViewModel
{
public string DocumentName { get; set; } = string.Empty;
public DateTime? DocumentDate { get; set; }
public ...
0
votes
1
answer
51
views
Pick line with the highest value of birth in every shop-country section
have been trying for several hours to resolve the problem but i cant sos
here is the tables im working with on pastebin
var result = E
.Join(A, a => a.ID, aa => aa.ID,
...
1
vote
1
answer
870
views
Merge two rows into single row based on a column using LINQ C#
I have a object list like below. I want to join every two rows into single row based on column B. It is sure that only two rows would be there for every single column B value.
Input
Output
However, ...
-1
votes
1
answer
424
views
trying to use linq aggregate function
I have below query where i am using the where clause with select and getting the result (list of librarySourceRowInputs) and would like to use the aggregate instead of (where and select).
In this ...
1
vote
1
answer
410
views
LINQ-to-Objects - cannot group by Object
I upgraded efcore 2.2 to 5 and simple group by is not working,
the data is already in memory, take a look:
List<IGrouping<Categories, Businesses>> businessesByCategory =
location....
0
votes
3
answers
175
views
LINQ : prevent creating of new object, ( appending to a list attribute if object exists )
( I am a beginner with C# )
I wants to create a list of Person class using 2 lists, List of Users and List of Post here is how the class structure looks. Problem : while Creating Object using LINQ, i ...
0
votes
1
answer
76
views
How can the input parameter of a LINQ to Objects expression be null
I have a collection of objects that I am trying to query with LINQ. Inexplicably, the code is crashing when querying for a specific value.
SomeObject[] myObjects = { ... };
foreach (int id in someIDs)...
0
votes
3
answers
610
views
How can I convert 'System.Collection.Generic.List<String>' into 'System.Windows.Documents.List'?
I have a table of doctors in my database. So I'm trying to get the list of the firstName of the doctors in my database.
In the ViewModel class I'm using this code to get it
public List DoctorsList ()
...
0
votes
1
answer
132
views
Linq Intermediate Object in method chain for Where and Select?
I am dealing with DocumentFormat.xml.
I need to do work to get to the data I need for the where clause.
But then I need to do the same work in the where clause to construct the desired object.
This ...
1
vote
2
answers
672
views
How to modify IEnumerable with LINQ to avoid foreach loop? [duplicate]
Can the following be done in LINQ as a one-liner, without using a for-loop?
IEnumerable<MyObj> MyList = EF.GetList(etc);
foreach (var row in MyList)
{
row.uploadedAt = MyUtils....
0
votes
1
answer
197
views
Get Max value from Lookup
I have a lookup like this:
ILookup<long ,float> vatPercentLookup = dataItems
?.GroupBy(x => x.VATRateId)
?.ToLookup(x => x.Key, z => z.Last().Percentage);
So i want to get max ...
0
votes
2
answers
149
views
How to populate my class object with linq to EF?
my class,
public class User
{
public string Username
{
get;
set;
}
public string Password
{
get;
set;
...
0
votes
1
answer
37
views
query subcollection when key and value are different subcollections - linq
I can't to query a collection like this below, in order to get the maximun "value" of a given "key", but key and value are subcollection of a collection
I need to get the max value of the "Revision" ...
0
votes
1
answer
35
views
How do i check string to see if all characters are integers, that it is 8 characters in length and throw an argument for each?
Class student and the main are just for reference.. In the try catch block there are two separate s1.SNum = "string" that should each throw a separate argument but both throw the same one every time ...
0
votes
0
answers
201
views
Does any Linq operator executes after 'where' yields no element? [duplicate]
(Edit after closing: the duplicate is not a duplicate of my question, but I found my answers within an explanation of lazy evaluation.)
Original question:
Disclaimers:
this is my 1st question here,
...
0
votes
3
answers
606
views
How to select list of objects inside another list of objects
public class Account
{
public List<Memo1> Memos { get; set; }
}
public class Memo1
{
public string Memo { get; set; }
public DateTime AddDate { get; set; }
public string UserID {...
0
votes
1
answer
54
views
How to Improvise Multiple queries on same collection with changing parameter values using LINQ to Objects
I need to fetch data based on below business requirement. We launch campaign's on items that we sell, which give the customer some discounts etc. We sell items of different brands, each brand has ...
-3
votes
3
answers
98
views
Linq to objects is 20 times slower than plain C#. Is there a way to speed it up?
If I need just the maximum [or the 3 biggest items] of an array, and I do it with myArray.OrderBy(...).First() [or myArray.OrderBy(...).Take(3)], it is 20 times slower than calling myArray.Max(). Is ...
1
vote
3
answers
447
views
Linq filter to avoid a loop
I am trying to formulate a LINQ query but not a pro at it so whatever I try is not working. I would like to filter the list to get email-ids from below list where score is 0 grouped by the Team Name.
...
3
votes
0
answers
37
views
Is there a "correct" way between these two statements that filter and return a boolean using LINQ to Objects? [duplicate]
I'm trying to determine if there is a correct way to first filter a collection and then determine if any items in the collections pass the filter condition. The two (basic) statements I'm trying to ...
0
votes
2
answers
421
views
How to filter a list of generic objects
I have find the code to implement a SortableBindingList that extends of BindingList and it theoretically let sort and filter a list of generic objects.
It works perfectly sorting the list but I can ...
0
votes
2
answers
55
views
how can i get a collection from an item in another collection that is also a collection
I would need:
a list(of employee) that contains all the employees contained in all companies. (e1,e2... e9)
the employee how has the oldest DischargeDate higher than 1/1/2018
I have solved it in ...
0
votes
2
answers
250
views
Search in the List Item Using C#
I have comma separated Id values like this: 3,4,5,7 and this differs for each records in the table.
Now from the configuration settings there are specific values like: 3,4
I need to have code that ...
3
votes
1
answer
3k
views
Use LINQ to concatenate multiple rows list with same value into single row
Group the repetitive value in the object list using Linq query.
I have the following data as table called "SudentAssessment" with these data.
AssessmentId Username SITSupervisor ...
0
votes
2
answers
883
views
Finding the minimum date value from a list of dates
This will give me a list of my Start Dates: ( they are stored as STRING )
var startDate = myValues.Select(t => t.StartDate).ToList();
I only need it to choose the earliest date value from it. And ...
0
votes
0
answers
76
views
Query objects for one to many relationship in LINQ
I have a problem which seems to be quite similar to
Query objects for one to many relationship in LINQ
I've been trying to solve my problem referring the above but somehow I've been failing for a ...
1
vote
1
answer
976
views
Linq where clause with nullable parameters
I'm trying to do a linq query which might have nullable params.
This is my linq call
listOfControlsVM = db.Controls.Where((status == null || s.Status.Description == status) && (impact == ...
-3
votes
3
answers
775
views
LINQ Performance Optimization
I have the following LINQ query that I want to optimize. Our system is heavily dependent on this, so even slight optimization will help over all. Any ideas are welcome, not sure where to even start..
...
0
votes
3
answers
824
views
Get Distinct using LINQ to Objects
My data looks like the following image
So i loaded it into a collection, using anon objects to bypass creating a class
List<dynamic> myList = new List<dynamic>()
{
...
-2
votes
1
answer
259
views
Linq - filter list
I am building a simple search tool in vb.net windows forms application with sql server database,
The user will enter a unique id and will see the results which shows the status.
Object Class:
...
0
votes
1
answer
724
views
How to query object with nested lists using linq?
I deserialize a JSON from a third-party provider into an object and want to query that object looking for a value in a specific property.
My problem is that the object has a property (Parts) whose ...
1
vote
1
answer
453
views
LINQ extension method to create Where query
I am trying to create an extension method that will be usable for both LINQ-to-Object and LINQ-to-Entities for creating a functioning Where query. More will go into it eventually but to start I am ...
1
vote
2
answers
115
views
How can I simplify this LINQ query that searches for keywords in strings and orders them by relevance?
Let's say I have some MyObjects and each of them have a Description property. I have a list of keywords that I want to use to search through the MyObject list. I want to order them in descending order,...
-1
votes
2
answers
290
views
Filtering Object values in C#
i've got a C# web Api receiving the following object :
"cars": {
"bmw": true,
"benz": false,
"kia": true,
"hyundai": false,
"madza": false,
"ford": ...
0
votes
2
answers
70
views
Using Linq to objects, how to get the total for the fields in the objects for different date?
I was looking to find the solution to my issue, but could not find exactly what I need, so I decided to create this question:
I have a list that contains objects. Those object are created based on ...
0
votes
3
answers
146
views
Sort List<T> on a property in a related List<T>
Say we have two List<T>. The first is a list of sales totals:
class SalesTotals
{
public Guid EmpID { get; set; }
public string EmpName { get; set; }
public decimal? TotalSales { ...
1
vote
0
answers
91
views
Performance of one big Select vs several chained selects
as in the question I wonder if it is better performance wise to make one big Select on a list or to make several small chained selects.
The second option for sure will be more readable as code is ...
0
votes
0
answers
69
views
Linq To object returns 0 values
I'm trying to get some data from to Lists using Linq. If I use join with equals using one field in each list it's ok and returns number of records as expected, but if I try use join on pair of fields ...
0
votes
0
answers
1k
views
Join list of objects on linq query
I try to join list of "Users" with list of "Receivers" and create ResultClass. There may or may not be Receiver object for user. Receiver object contains list of UserIds and I want these Id:s to be ...