Questions tagged [linq-to-objects]

The term "LINQ to Objects" refers to the use of LINQ queries with any IEnumerable or IEnumerable collection directly, without the use of an intermediate LINQ provider or API such as LINQ to SQL or LINQ to XML.

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.

For example, say that myCats is a list of Cat objects. Then you can pick your favorite cat by using:

Cat myFavorite = myCats.Single(c => c.Score == myCats.Max(x => x.Score));

To get an alphabetical listing of your cats, use this:

var listing = myCats.OrderBy(c => c.Name);

To get all cats that have caught more than 20 mice, use the following:

var champions = myCats.Where(c => c.MiceCaught.Count > 20);

You can also use a more SQL-like syntax:

var champions = from cat in myCats where cat.MiceCaught.Count > 20 select cat;

LINQ to Objects thus uses the same familiar syntax as the other LINQ implementations such as LINQ to Entities and LINQ to SQL.

1356 questions
-1
votes
1 answer

SQL to Linq Conversion

I have sql as below SELECT Q.MaterialID AS MaterialID, Q.ProductID AS ProductID, QB.Quantity AS Quantity, Q.ParameterID AS ParameterID, SUM((Q.ParameterValue * Q.Quantity)/Q.TotalTonnes) AS ParameterValue FROM @Quality Q INNER JOIN…
Sreedhar
  • 29,307
  • 34
  • 118
  • 188
-1
votes
2 answers

I'm looking for a LINQ solution to create a sub-list where items w/ duplicate property values are skipped

The problem is: I have a list of objects, with some containing the same PlanId property value. I want to only grab the first occurrence of those and ignore the next object with that PlanId. The root problem is a View in the database, but it's tied…
Yatrix
  • 13,361
  • 16
  • 48
  • 78
-2
votes
1 answer

Linq to file system to get last created file with different extensions in each sub folders

see my post. Here I am getting latest created file in each sub folder, but I need to get the latest created files with different extensions. For example, there are five sub folders each containing more than one PDF file and more than one Excel file,…
Kuttan Sujith
  • 7,889
  • 18
  • 64
  • 95
-2
votes
1 answer

LINQ: Get subset based on size

I have an Object named Item: public class Item { public Guid Id { get; set; } public long Size { get; set; } } in a List What I need is to query this list and return a number of rows where the cumulated size (Size property of…
SolarX
  • 1,873
  • 2
  • 18
  • 26
-2
votes
1 answer

Why won't it sort my ICollection correctly using the instance method OrderByDescending?

I have an ICollection Jardin which I want to sort according to some property Plante.Taille: private readonly ICollection Jardin; I use the instance method OrderByDescending : public void TriDesc() { Console.WriteLine("Tri par…
Gui Gui
  • 7
  • 2
-2
votes
1 answer

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: Public Class IStatus …
MAF
  • 27
  • 9
-2
votes
1 answer

How to define classes such that there will be only one Product object and multiple Product Details objects in c#

Can someone give example how to "define classes such that there will be only one Product object and multiple Product Details objects in c#"?
Shakeer Hussain
  • 2,230
  • 7
  • 29
  • 52
-2
votes
1 answer

How to do Linq to object

I am having a list of objects as follows List creditOptions = new List(); creditOptions = (List)pGateways; The data filled in creditOptions is coming from a server in json format and it keeps on changing. It has some…
-2
votes
1 answer

How to sort an arraylist with nest class column?

I have code shows below. I want get an sorted list by each word shows times in the paragraph "s". The final list suppose orderbydescending "times". void Main() { string s = "Using the Thread class The Thread class can be found in the…
Deep in Development
  • 497
  • 2
  • 8
  • 24
-2
votes
1 answer

include group by in c# linq query

I have this linq query which I want to include group by some specific fields: from x in db.Schedule join y in db.Schedule on x.ID equals y.ID - 1 join z in db.Locations on x.Line.ToString() + '-' + x.Expedition equals z.LocationCode where…
Laziale
  • 7,965
  • 46
  • 146
  • 262
-2
votes
2 answers

How to view Generated SQL statements by LINQ when querying object?

when we use linq to sql then few visualizer exist which show us what sql is generating by linq but when we query object by linq then is there any way out to have similar sql statement. as exmple string[] names = new string[] { "Jon Skeet",…
Thomas
  • 33,544
  • 126
  • 357
  • 626
-2
votes
2 answers

Linq to objects C# nested class

public class parent { public string abc { get; set; } public childclass pos { get; set; } } public class childclass { public string value { get; set; } } I am currently reading the collection of parent class var obj = (from dia in…
user1005310
  • 737
  • 2
  • 12
  • 40
-3
votes
3 answers

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 there a way to write a faster linq query? This is…
Jeno Csupor
  • 2,869
  • 6
  • 30
  • 35
-3
votes
3 answers

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.. using System; using…
scorpion5211
  • 1,020
  • 2
  • 13
  • 33
-3
votes
1 answer

Returning NullReferenceException while trying to get Element by name

I am experimenting the features of linq to xml, while trying to simulate the method XElement.Descendants("Users"), I have the following code; my question is why the second line var usersElement = xElement.Element("Users"); // this is returning…
Dongming Yan
  • 123
  • 9
1 2 3
90
91