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.

1347 questions
-1
votes
1 answer

Parent navigation property is `null` when selecting child object

I have two classes that partake in a parent-child relationship. The parent class is Country, and the child class is City: public partial class Country { public Country() { this.Cities = new List(); } public int Id {…
Developerzzz
  • 1,041
  • 1
  • 11
  • 23
-1
votes
1 answer

Linq Filter Array of Delimited Strings

I have a string like this: RoleId,RoleName|CategoryId,CategoryName I split them first like this: string delm = "RoleId,RoleName|CategoryId,CategoryName"; string[] FieldsToReplace = attributes[0].IdsToReplaceWith.Split('|'); Suppose i have a…
Ehsan Sajjad
  • 59,154
  • 14
  • 90
  • 146
-1
votes
2 answers

Linq query to array

This is currently my Linq query: result = From d In dc.Tracker Where d.Responsible.Value = "first last name" Order By d.Priority1, d.Deadline Select New With { _ Key .Title = d.Name, _ Key .Description = d.Priority1, _ …
StealthRT
  • 9,252
  • 35
  • 155
  • 302
-1
votes
2 answers

Top 10 Percentile by salary of results

I have a in-memory List of Job objects, were the Job object has a propery called Salary. How do I use LINQ or C# to filter this list to only contain the list of jobs with salaries in the top 10 or bottom 10 percentile? Here is my attempt, which…
Abe
  • 5,806
  • 11
  • 44
  • 74
-1
votes
2 answers

Transform objects using linq

Class A has following properties: public int A_Id { get; set; } public IEnumerable B_Ids { get; set; } The collection of A that contains: A_Id = 1, B_Ids = {101, 102, 103} A_Id = 2, B_Ids = {104} A_Id = 3, B_Ids = {105, 106} From the…
Mike
  • 29
  • 3
-1
votes
2 answers

C# Function that converts a string to a dictionary

I have a function that converts a string to a dictionary using the code below. I need to add a 3rd delimiter that is essential a row or record delimiter. Currently "," delimits [attribute,value] and "|" delimits each pair. I can't figure out how…
GoBeavs
  • 479
  • 2
  • 9
  • 21
-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
  • 26,251
  • 31
  • 104
  • 163
-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
  • 12,038
  • 13
  • 39
  • 73
-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,661
  • 18
  • 60
  • 89
-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,739
  • 2
  • 16
  • 26
-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
  • 17
  • 7
-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
  • 1,636
  • 4
  • 17
  • 41
-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
2 answers

Method 'System.String GetState(int32)' has no supported translation to SQL

I'm using the below code to fetch the state. I'm getting the error" Method 'System.String GetState(int32)' has no supported translation to SQL".Please let me know where i'm doing a mistake. public IQueryable GetResult() { …
Naresh Reddy
  • 37
  • 1
  • 5
-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
  • 485
  • 2
  • 7
  • 23
1 2 3
89
90