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
0
votes
2 answers

Nested foreach to change list items

I need to change items in a list using nested for/foreach loops. Problem is that I could not get it working using LINQ with or without dot notation. The traditional way worked and goes like this: foreach (MapObjectLayer mapObjectLayer in…
Raymond Holmboe
  • 2,061
  • 1
  • 16
  • 18
0
votes
3 answers

Replace letter ي with letter ی in linq?

i want Replace بازي to بازی var List = (from darkhast in Tbl_Darkhast.Where(d => d.Address.Replace("ی","ي").StartsWith( Address.Replace("ی","ي") ) ) select new { .... }
Younes Koopai
  • 51
  • 1
  • 11
0
votes
2 answers

How can I get the distinct items of the following data structure in C# / LINQ?

I have the following objects: public class Agency { public int ID; public IEnumerable BusinessUnits; } public class BusinessUnit { public int ID; public decimal AmountSpent; public IEnumerable
KingNestor
  • 65,976
  • 51
  • 121
  • 152
0
votes
1 answer

LINQ DateTime Aggregation with GroupBy and Group By

I've a List of TimeInterval data that are 30 minute apart as shown below: List testData = new List(); testData.Add(new TimeInterval() { Start = DateTime.Parse("2012-05-09 6:00:00 AM"), End = DateTime.Parse("2012-05-09…
Nil Pun
  • 17,035
  • 39
  • 172
  • 294
0
votes
1 answer

LINQ query to transform CSV data

I'm new to LINQ and hoping someone can help me out writing this query to transform some data. I have a Dictionary containing data like this.... <01/07/12 00:00,…
ColinCG
  • 57
  • 4
0
votes
1 answer

Entity Framework How to bind textbox to model in Windows Forms

Using Entity data model in a Windows Forms Project, I want to bind simultaneously Orders entity to datagridview and to textBox, and textBox has to display OrderID value depending on the current line in the datagrid. The code I used in Form load…
Sami-L
  • 5,553
  • 18
  • 59
  • 87
0
votes
1 answer

Sorting ASP.NET ListView that was DataBound with Custom Projection

So here's the scenario - I started by querying data from tables transactions and v_patients. I execute that query to a List(Of transaction). I manipulate (Concat(), GroupBy(), etc.) that list until I reach a final projection and DataBind() to…
ffrugone
  • 51
  • 7
0
votes
1 answer

LINQ query optimization

I retrieve data from two different repositories: List allFs = fRepository.GetFs().ToList(); List allEs = eRepository.GetEs().ToList(); Now I need to join them so I do the following: var EFs = from c in…
Sev
  • 761
  • 4
  • 16
  • 29
0
votes
1 answer

LINQ to JSon response

I have posted my class below and with sample data. I need to pass this class as an json response. [Serializable] public class Student { public string Fname {get;set;} public string FirstSemMarkcsv {get;set;} //This should hold marks as…
ashish.chotalia
  • 3,696
  • 27
  • 28
-1
votes
4 answers

LINQ - Convert to LAMBDA Expression

foreach (int i in temp) data.Add(i); where temp is a List and data is an ObservableCollection
-1
votes
1 answer

How to select common items

Work on C# linq.I have a list to list.From this list I want to get the common items List oParent = new List(); List> oChild = new…
shamim
  • 6,640
  • 20
  • 85
  • 151
-1
votes
3 answers

Generic collection fill by var value

In my code, I need help to put result value into oList NorthwindDataContext db = new NorthwindDataContext(); List oList = new List(); var result = from p in db.Categories select new { CategoryID = p.CategoryID,…
shamim
  • 6,640
  • 20
  • 85
  • 151
-1
votes
1 answer

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 process I am trying to access the same variables…
Glory Raj
  • 17,397
  • 27
  • 100
  • 203
-1
votes
1 answer

Need to determine smallest value in a List

I'm stuck at something that seemed easy but became a headache pretty fast: Here is a class that represent a structure I'm using: public class LocumJobDistanceDifferenceObject { public LocumJobDistanceDifferenceObject(Int64 ALocumID, Int64…
DoomerDGR8
  • 4,840
  • 6
  • 43
  • 91
-1
votes
2 answers

How can i use LINQ with property

Hi I have a array list if type class "DtContract". ArrayList listOfContracts_; foreach (DTContract contract in listOfContracts_) { if (contract.Engine != DTIsland.EngineType.AMADEUS && contract.Engine !=DTIsland.EngineType.SABRE) …
Shivi
  • 1,075
  • 9
  • 24
  • 42