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
0
votes
1 answer

Linq join ,group and sum

I have this: I have three lists with data orders orderlines and addresses. I want to join these lists. Contents = from o in Orders join a in addresses on o.DeliveryAddressId equals a.AddressId //join ol in ordersLines on…
espvar
  • 995
  • 5
  • 13
  • 27
0
votes
1 answer

Can I use linq to join two result sets on an ordinal/ index #?

I'm trying to use linq to objects with html agility pack to join two result sets on their relative ordinal position. One set is a list of headers, the other is a set of tables, with each table corresponding to one of the header values. Each set has…
StatsViaCsh
  • 2,420
  • 8
  • 40
  • 61
0
votes
1 answer

How to use selectmany in linq?

The following is my linq query var meetingIndividualQuery = meetingsList.SelectMany(o => o.Attendies.Distinct().Where(x => x.CompanyId == company.CompanyId)); I have the following class public class Meetings { public string…
Shailesh Jaiswal
  • 3,392
  • 13
  • 66
  • 117
0
votes
3 answers

linq to object getting the correct pattern

i have my records as follows mazhar-kaunain-baig-5 mazhar-kaunain-baig-5-6 mazhar-kaunain-baig this is my query ptype = _pagecontext.PagesRefs .Where(m => m.nvcr_Slug.Contains(str+ "-") && m.bit_Active == true) …
maztt
  • 11,509
  • 19
  • 73
  • 147
0
votes
2 answers

Advanced GroupBy

I have a List of items with following structure: Id DateTime Weight How can group them by Id and Date of Date field (which is DateTime) and have the total weight of the group? I want something like this: Id Date TotalWeight
Reza Owliaei
  • 3,098
  • 5
  • 30
  • 52
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
  • 1,813
  • 1
  • 14
  • 15
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
  • 49
  • 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
  • 59,315
  • 50
  • 115
  • 149
0
votes
0 answers

Linq query suggestion?

I am using linq2sql in my application i am just stuck with this simple query. my stored procedure returning following id order type text 1 1 header Personal details 2 2 body text Name 3 3 body text Address…
Bumble
  • 517
  • 2
  • 8
  • 22
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
  • 16,019
  • 34
  • 150
  • 277
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
  • 4,859
  • 15
  • 51
  • 77
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
  • 751
  • 4
  • 15
  • 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,558
  • 24
  • 27