Skip to main content

Questions tagged [linq]

Language Integrated Query (LINQ) is a Microsoft .NET Framework component that adds native data querying capabilities to .NET languages. Please consider using more detailed tags when appropriate, for example [linq-to-sql], [linq-to-entities] / [entity-framework], or [plinq]

1821 votes
7 answers
790k views

Multiple "order by" in LINQ

I have two tables, movies and categories, and I want to get an ordered list by categoryID first and then by Name. The movie table has three columns ID, Name and CategoryID. The category table has two ...
Sasha's user avatar
  • 20.7k
1491 votes
23 answers
1.3m views

LINQ's Distinct() on a particular property

I am playing with LINQ to learn about it, but I can't figure out how to use Distinct when I do not have a simple list (a simple list of integers is pretty easy to do, this is not the question). What I ...
Patrick Desjardins's user avatar
1373 votes
21 answers
774k views

Difference Between Select and SelectMany

I've been searching the difference between Select and SelectMany but I haven't been able to find a suitable answer. I need to learn the difference when using LINQ To SQL but all I've found are ...
Tarik's user avatar
  • 81.1k
1292 votes
10 answers
1.9m views

Group by in LINQ

Let's suppose if we have a class like: class Person { internal int PersonID; internal string car; } I have a list of this class: List<Person> persons; And this list can have ...
test123's user avatar
  • 14.1k
1217 votes
14 answers
283k views

Returning IEnumerable<T> vs. IQueryable<T>

What is the difference between returning IQueryable<T> vs. IEnumerable<T>, when should one be preferred over the other? IQueryable<Customer> custs = from c in db.Customers where c....
stackoverflowuser's user avatar
1186 votes
15 answers
797k views

Group By Multiple Columns

How can I do GroupBy multiple columns in LINQ Something similar to this in SQL: SELECT * FROM <TableName> GROUP BY <Column1>,<Column2> How can I convert this to LINQ: ...
Sreedhar's user avatar
  • 29.8k
1149 votes
22 answers
1.1m views

LINQ query on a DataTable

I'm trying to perform a LINQ query on a DataTable object and bizarrely I am finding that performing such queries on DataTables is not straightforward. For example: var results = from myRow in ...
Calanus's user avatar
  • 26.1k
955 votes
14 answers
768k views

When to use .First and when to use .FirstOrDefault with LINQ?

I've searched around and haven't really found a clear answer as to when you'd want to use .First and when you'd want to use .FirstOrDefault with LINQ. When would you want to use .First? Only when you'...
Metro Smurf's user avatar
883 votes
22 answers
715k views

LINQ equivalent of foreach for IEnumerable<T>

I'd like to do the equivalent of the following in LINQ, but I can't figure out how: IEnumerable<Item> items = GetItems(); items.ForEach(i => i.DoStuff()); What is the real syntax?
tags2k's user avatar
  • 83.7k
872 votes
34 answers
369k views

What is the Java equivalent for LINQ? [closed]

What is Java equivalent for LINQ?
Ahmed Atia's user avatar
  • 17.9k
866 votes
11 answers
680k views

IEnumerable vs List - What to Use? How do they work?

I have some doubts over how Enumerators work, and LINQ. Consider these two simple selects: List<Animal> sel = (from animal in Animals join race in Species ...
Axonn's user avatar
  • 10.3k
853 votes
12 answers
351k views

LINQ Aggregate algorithm explained

This might sound lame, but I have not been able to find a really good explanation of Aggregate. Good means short, descriptive, comprehensive with a small and clear example.
Alexander Beletsky's user avatar
784 votes
14 answers
871k views

Using LINQ to remove elements from a List<T>

Say that I have LINQ query such as: var authors = from x in authorsList where x.firstname == "Bob" select x; Given that authorsList is of type List<Author>, how can ...
TK.'s user avatar
  • 47.5k
754 votes
24 answers
333k views

Dynamic LINQ OrderBy on IEnumerable<T> / IQueryable<T>

I found an example in the VS2008 Examples for Dynamic LINQ that allows you to use a SQL-like string (e.g. OrderBy("Name, Age DESC")) for ordering. Unfortunately, the method included only ...
John Sheehan's user avatar
  • 77.9k
743 votes
12 answers
665k views

Use LINQ to get items in one List<>, that are not in another List<>

I would assume there's a simple LINQ query to do this, I'm just not exactly sure how. Given this piece of code: class Program { static void Main(string[] args) { List<Person> ...
JSprang's user avatar
  • 12.8k

15 30 50 per page
1
2 3 4 5
5780