Is there any feature similar to LINQ (.NET) in different languages like JAVA, PHP, etc?
-
1Are you asking for similar syntax or library features? – Gabe Jun 06 '10 at 18:38
-
http://stackoverflow.com/questions/346721/linq-for-java-tool duplicate – Bozho Jun 06 '10 at 18:40
-
2Check this one: github.com/nicholas22/jpropel, example:new String[] { "james", "john", "john", "eddie" }.where(startsWith("j")).distinct(); – NT_ Oct 07 '11 at 20:28
-
For Scala: https://github.com/nicholas22/propelS – Scooterville Jun 09 '12 at 21:29
7 Answers
There are many languages that have syntax or library functions for operating on sequences of objects in a mostly functional way. For example Python has lambda functions, list comprehensions, generators, and the itertools
module.
However I don't know of any language that can get anywhere near everything that LINQ can do as cleanly and concisely. Remember that LINQ is not just a way to operate on in-memory structures - LINQ has many providers that share a similar interface:
- LINQ to Objects
- LINQ to XML
- LINQ to SQL
- etc..
Microsoft have done a good job with LINQ. I am sure some other languages will take inspiration from the success of LINQ and consider how to add similar features in the near future.

- 811,555
- 193
- 1,581
- 1,452
Scala has for-comprehensions that provide similar functionality as the LINQ.
Example: Find all attendees with name Fred that speak Danish.
C#:
var xs =
from att in attendees
where att.name == "Fred"
from lang in att.spokenLanguages
where lang == "Danish"
select att;
Scala:
val xs = for {
att <- attendees
if att.name == "Fred"
lang <- att.spokenLanguages
if lang == "Danish"
} yield att

- 90,905
- 62
- 285
- 365
Im really surprised that nobody has talked about it, but I've used a port of LINQ to PHP from Martin Balliauw, which works kinda nice. It works kinda well, you can do something like this:
$result = from('$employee')
->in( $employeeTable )
->where('$employee => strlen($employee->Name) < 5')
->orderBy('$employee->Name')
->select('$employee');
I even wrote a small blog post about it.

- 4,631
- 2
- 35
- 48
This is valid Java, but needs this library: https://github.com/nicholas22/jpropel-light
import java.util.Arrays;
import lombok.ExtensionMethod;
import lombok.val;
import propel.core.utils.Linq;
import static propel.core.functional.predicates.Predicates.*;
import static propel.core.functional.projections.Projections.*;
@ExtensionMethod({Linq.class})
public class Main
{
/**
* @param args
*/
public static void main(String[] args)
{
val names = new String[] { "john", "james", "john", "eddie" }.where(startsWith("j")).distinct();
System.out.println(Arrays.toString(names));
// prints "[john, james]"
}
}

- 2,660
- 23
- 25
While basic LINQ features, like Select
(map
) and Where
(filter
) are present in almost all contemporary programming languages, constructing SQL "on the fly" and lazily is a work for ORM
For example, Django ORM allow you to use such syntax for making a query:
Posts.objects.filter(user=peter).annotate(comment_count=Count('comment')).order_by('comment_count')
It's something like (not very sure) in LINQ:
from p in posts
where p.user == peter
select new { post = p, comment_count = comments.Where(c => c.post == p).Count() }
order by comment_count

- 9,965
- 10
- 60
- 84
Sure there are, but php is a programming language and not a framework like .net framework. So if you want to use features, you should download some libraries, orms or frameworks to get higher effectivity. I dont think that php has that powerful feature, that could be an equivalent of linq.

- 2,050
- 2
- 25
- 39
-
LINQ is not part of ASP.NET, per se. It's part of the .NET Framework. ASP.NET is also part of the .NET Framework. The types in the .NET Framework can be used in any .NET language. Both VB.NET and C# are .NET languages that happen to have language syntax that makes the LINQ features of the .NET Framework easier to use. – John Saunders Jun 06 '10 at 19:03
http://code.google.com/p/phpreboot/ implements LINQ partially in a PHP-like language.

- 144,265
- 20
- 237
- 291