Linq to Objects is a version of the Linq query engine for in-memory object collections. You use Linq to Objects to query a list of objects based on their properties.

learn more… | top users | synonyms (1)

1
vote
1answer
40 views

How to remove two objects with the same ID but different date values with LINQ to objects

I have a List<dynamic> in which I have N records with the same ID but different ValidTo/ValidFrom values. Say I had these objects: Id: 1, ValidFrom: 1/1/2012, ValidTo: 1/1/2015 Id: 1, ...
0
votes
2answers
39 views

linq query repeated columns in a list

I have a table similar to the one below. Branch Dept Product ID Product Val Product Date Branch 1 Dept 1 ID 1 1 5/23/2013 Branch 1 Dept 1 ID 2 ...
1
vote
2answers
38 views

List<Info> where Info has Last and First properties map to Dictionary<Last,List<First>>

If I have a class of type class Info { public Info(string first, string last) { this.First = first; this.Last = last; } string First { get; private set; } string Last { get; private set; ...
2
votes
1answer
46 views

Runtime creation of LINQ expression

Say I have this expression: int setsize = 20; Expression<Func<Foo, bool>> predicate = x => x.Seed % setsize == 1 || x.Seed % setsize == 4; ...
0
votes
2answers
36 views

Contains in Linq to Object?

I have the following Lists : var list1 = new List<string> {"m1", "m2", "m3"}; var list2 = new List<List<string>> { new List<string>{"m1", "m2", "m3"},//1 ...
1
vote
0answers
27 views

“Cannot be translated into a LINQ to Entities …”, but it should

This sould be able to be translated into a Linq to entities store expression, but it throws that it cant. for (int day = 1; day <= 7; day = day + 1) pairs.Add("[" + day + ", " + ...
0
votes
2answers
50 views

LINQ to Objects converting to list to display in gridview

I am trying to use LINQ to Objects to bind a list of books to a gridview. Author and Book are custom objects, where "Books" is defined in the Author class as a list. List<Author> authors = ...
0
votes
1answer
29 views

How use LINQ to find entities where a list of sub entities contains another list

I have a complex object which contains 2 lists of more complex objects. The first object is as follows: public object1 { public string Name { get; set; } public virtual ...
0
votes
1answer
76 views

LINQ not working

I’ve a class as :- Class EmployeesList { public string Category{get;set;} public string Name{get;set;} } And a list<EmployeesList> as ListOfEmployee :- Category = “AA” Name= “A” ...
0
votes
2answers
61 views

LINQ to Objects

I have an object, built upon a XML schema and want to use LINQ to get the data out of it which I'm interested in :) The structure look like the following example : SimulationStep [1..n] - ...
0
votes
3answers
57 views

How to do LINQ Cross Join With Dot Notation

I know how to write a query notation join in dot notation, but how do you write a cross join in dot notation? List<Alpha> als = new List<Alpha>{new Alpha(), new Alpha()}; ...
0
votes
2answers
64 views

Remove and reorder list elments

Is it possible to solve the following problem WITHOUT using C# loop (foreach; for; while; etc) but only C# Linq or lambda expressions? Problem: Given a list of Task objects and a list of removed ...
0
votes
1answer
62 views

How to get the correct data with a linq statement

The question evolved from the original post, so to broaden the results I have added a seperate question. the original quest was answered, but in doing so I ran into a new problem that has stumped me. ...
2
votes
1answer
25 views

IEnumerable query with GroupBy with Min and Projection

I have these arrays correlated by index. So for each index (ObjId, ObjState) form a pair. string[] ObjIds = { "Obj1", "Obj1", "Obj2", "Obj2", "Obj1", "Obj3", "Obj2", "Obj2" }; string[] ObjStates = ...
9
votes
4answers
101 views

Error creating a Linq query

I've a query like this one struct MyStruct { public string name; public double amount; } var a = from p in Products select new MyStruct { name = p.Name, amount = p.Amount }; ...
0
votes
1answer
50 views

Statement is not updating data item

I have this LINQ statement that tries to set the 1st element in the collection of string[]. But it doesn't work. Below is the LINQ statement. docSpcItem.Where(x => x.DocID == 2146943) ...
0
votes
1answer
137 views

Put value in datatable group by week

I have a datatable which comprises values from 1st January to march, something like this: DATE Employer Job1 Job2 1/4/2013 A 1.3 2 1/4/2013 B 2.5 6 ...
-1
votes
1answer
84 views

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

Linq to Objects Sum to List

Im designing a method that accepts a List<Bar>, and returns <List>BarGroup, grouped by Bar.barName. My guess is I need to use Aggregate with List.Add, but I am fairly new to lambdas and ...
0
votes
1answer
38 views

Search List content using Linq

I have List of object which contains values in following pattern 2$FirstLevel+HRMS 2#40#56$SecondLevelOperation+Add 2#60$SecondLevel+dffddfdf Using Linq i want to select the record which contains ...
0
votes
2answers
76 views

Linq to Objects to query LLBLGen projection

I'm trying to use the recommended LLBLGen syntax to query a projection ...
0
votes
1answer
32 views

Finding Max of different fields

Public class Inquiry { Public Date Inquirydate; Public Date submittedDate; Public Date VerifiedDate; } List<Inquiry> InquiryList= new List<Inquiries>(); Form this collection I need to ...
0
votes
1answer
77 views

Is it possible to select multiple variables with LINQ without using keyword new?

Is there any way to select both a and b without new keyword in the following code ? (from a in Enumerable.Range(1, 9) from b in Enumerable.Range(1, 9) select a,b).ToArray(); EDIT My goal was to ...
1
vote
3answers
46 views

Method for checking consistents of numbers in list of object

What I'm trying to do is make a method that will be able to figured out if some int isn't a consistent in my List of numbers (method should return missing numbers) For example if I have ...
1
vote
1answer
57 views

Sort list of objects by list of objects inside it

I have home object : id , FirstName, Lastname, Fees[ ] Fees is object contain Amount description home object include the Fees array I have list of homes and every home has array/list from fees I ...
1
vote
1answer
32 views

Selecting nth values in anonymous types

I have a collection of HTML items after running an XPATH expression against an instance of HtmlDocument (HTMLAgilityPack). The returning collection is: The {h3} tag should be name of ...
0
votes
4answers
116 views

Is it possible that a LINQ (to Object) query contains infinite loop?

I have a simple class: public class RawBomItem { private string material; private string item; private string component; private string quantity; private string b; private ...
0
votes
2answers
35 views

How to maintain counters with LinqToObjects?

I have the following c# code: private XElement BuildXmlBlob(string id, Part part, out int counter) { // return some unique xml particular to the parameters passed // remember ...
2
votes
1answer
58 views

Select multiple where on same column

Given the following code: var filtered = (from a in lijst select a); foreach (string brandstof in checkedListBoxHoofdbrandstof.CheckedItems) { MessageBox.Show(brandstof); filtered = (from a ...
3
votes
1answer
216 views

SortedSet / SortedList with better LINQ performance?

Let's say we have a sorted collection such as SortedSet or SortedList with many (10M+) elements. Lots of querying is happening, so performance matters. From runtime comparisons, I'm under the ...
0
votes
3answers
57 views

Distinct items on property from 2 lists

I got a Person class that looks like this: Person1: Id=1, Name="Test1" Person2: Id=2, Name="Test2" Person3: Id=3, Name="Test3" And an IEnumerable<int> with unique Person id's: var personIds ...
0
votes
1answer
55 views

Filter nested DTOs with key

I have List of DTO Suach as : Public Class UKey { public Int64 Key{ get; set; } } Public Class Test : UKey { public Int64? CityId { get; set; } public Test2 test2{ get; set; } } ...
1
vote
2answers
370 views

LINQ SelectMany and Where extension method ignoring nulls

I have the below example code, and I am interested to know how I can make this any cleaner, possibly through better use of SelectMany(). At this point the QuestionList property will not be null. All I ...
2
votes
1answer
97 views

Need a linq to objects query for a nested collection

I am trying to select text from a collection that is three of four deep. RootObject has a List<ResourceSet> resourceSets The resourceSets has a List<Resources> resources The resources ...
0
votes
2answers
47 views

Join all the sublists together and grab the first one

I want to be able to pull the last invoice containing a product in a category Category->Product->Invoice (from p as Product in cat where p.InvoiceList.Where(function(o) o.InvoiceDate >= MAX_ONE) ...
1
vote
1answer
229 views

Querying Two data tables asp.net

I have 2 tables each with same fields basically containing table1.ItemCode table1.Qty table2.ItemCode table2.Qty i am querying these two tables from sql by the following command SELECT ...
0
votes
3answers
344 views

Select top N with record from DataTable with some sorting using Linq

I have created a DataTable. I have populated the rows of the DataTable after some operations. I am very new to Linq I want to Get the Top "N" Records from the DataTable implementing also some paging. ...
0
votes
3answers
149 views

LINQ Get Properties of Class

How can I get list of properties of a object/class using linq?? public class Person { public string Name { get; set; } public string Age { get; set; } public string Gender { get; set; } } ...
0
votes
0answers
26 views

Convert this Linq code to regular/non linq code

I am new to Linq and working on someone's code who was quite the opposite. He wrote this code below. I understand the code but can anyone tell me if i can convert this code to non linq in almost the ...
1
vote
3answers
936 views

Linq select objects in list where exists IN (A,B,C)

I have a list of orders. I want to select orders based on a set of order statuses. So essentially select orders where order.StatusCode in ("A", "B", "C") // Filter the orders based on the ...
9
votes
2answers
125 views

Does LINQ to Objects keep its order

I have a List<Person> and instead want to convert them for simple processing to a List<string>, doing the following: List<Person> persons = GetPersonsBySeatOrder(); ...
2
votes
2answers
119 views

LINQ GroupBy x where there is more then one x and y is unique

Let there be an objects like so: class foo { public String x{ get; set; } public String y{ get; set; } } var bar = new List<foo> { new foo{ x= "u", y= "w"}, new foo{ x= "s", y= "q"}, ...
0
votes
3answers
69 views

Unexpected Behavior from a Linq Contains() Method

In a filter of customers, this statement returns all customers with any part of the selectedIDs in their CustomerID. For example, selectedIDs value '1' returns CustomerID '1' and '10'... if ...
-1
votes
2answers
27 views

Transform objects using linq

Class A has following properties: public int A_Id { get; set; } public IEnumerable<int> B_Ids { get; set; } The collection of A that contains: A_Id = 1, B_Ids = {101, 102, 103} A_Id = 2, ...
2
votes
3answers
80 views

Can't find the appropriate operators for a Linq query

I need help building a Linq query. I have this dictionary : var dict = new Dictionary<string, IDictionary<int, double>> { { "one", new Dictionary<int, double> { ...
1
vote
7answers
72 views

changing item position in a list

I have this code through which I filter and get a set of groups var groups = Items.Select(g => g.Category).Distinct(); Now in the list I also get a empty group "" which I want to place at the ...
0
votes
10answers
100 views

Get element from a List<Class> of classes

I have a class called Employee that represents each employee in a company. public class Employee { public string FirstName { get; set; } public string LastName { get; set; } public int ...
0
votes
4answers
73 views

LINQ GroupBy and Select on different property

If I have the following collection: var foos = new List<Foo> { new Foo{ Name = "A", Value = 1 }, new Foo{ Name = "B", Value = 1 }, new Foo{ Name = "B", Value = 2 }, new Foo{ ...
0
votes
1answer
62 views

ToLookup vs. ReadOnlyCollection

I've been using LINQ-to-objects for quite a while, but I just now noticed the Enumerable.ToLookup extension method and read its documentation. I came across it while looking for the quickest way to ...
0
votes
0answers
170 views

Not able to make linq work with datatable to generate recursive list ul

I need to generate unordered list menu from a datatable, So far i was not able to find a code which will recursive look through the table and generate list to any level I found this code which looks ...

1 2 3 4 5 21