Linq 和 Entity Framework 的 Java 等价物是什么

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1083080/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 23:22:47  来源:igfitidea点击:

What are the Java equivalents to Linq and Entity Framework

javalinqentity-framework

提问by Colin Desmond

Having played with Linq (to SQL and Objects) as well as the Entity Framework from Microsoft recently, I was wondering what the non-.Net (specifically Java) equivalents are?

最近使用了 Linq(到 SQL 和对象)以及 Microsoft 的实体框架,我想知道非 .Net(特别是 Java)等价物是什么?

回答by Landon Kuhn

Java does not have a Linq equivalent. However Scala, a functional language that compiles to Java byte code, has something closes: an extended for loop syntax.

Java 没有等效的 Linq。然而,Scala 是一种编译为 Java 字节码的函数式语言,它有一些封闭的东西:扩展的 for 循环语法。

回答by codethulhu

There is a Java project called JoSQLwhich provides object querying capabilities with a SQL-like syntax.
While I haven't used it myself, I know that it is used in some heavyweight applications.

有一个名为JoSQL的 Java 项目,它提供具有类似 SQL 语法的对象查询功能。
虽然我自己没有使用过它,但我知道它被用于一些重量级的应用程序中。

回答by Apocalisp

Have a look at JaQue.

看看杰奎

回答by ykaganovich

For database-heavy work, SQLJmight be an option. The downside is it's not pure Java and requires a pre-processor.

对于数据库繁重的工作,SQLJ可能是一种选择。缺点是它不是纯 Java 并且需要预处理器。

回答by Timo Westk?mper

Consider using Querydsl : http://www.querydsl.com

考虑使用 Querydsl:http://www.querydsl.com

It supports JPA/Hibernate, JDO, SQL and Collections.

它支持 JPA/Hibernate、JDO、SQL 和集合。

Querydsl is fully type-safe, supports autocomplete in IDEs and provides a common querying syntax on top multiple backends.

Querydsl 是完全类型安全的,支持 IDE 中的自动完成并在多个后端提供通用查询语法。

I am the maintainer of Querydsl, and I wrote a comparison to other frameworkssome time ago.

我是Querydsl的维护者,前段时间写了一篇与其他框架对比

It is slightly biased, but shows the different emphasis

略有偏颇,但显示了不同的侧重点

  • statically typed or not
  • which backends are supported
  • is the interface for query construction cascading or not
  • 静态类型与否
  • 支持哪些后端
  • 是不是查询构造级联的接口

Newer frameworks experiment also with closure syntax.

较新的框架也在尝试使用闭包语法。

回答by i.petruk

There is no exact alternative which is universal as LINQ is. However if we are talking about LINQ to SQL then JPA is really an alternative when you use it with an IDE that supports "Inject language" feature. E.g. IDEA will do full scale completion of the JPA query within a string

没有像 LINQ 那样通用的确切替代方案。但是,如果我们谈论的是 LINQ to SQL,那么当您将 JPA 与支持“注入语言”功能的 IDE 一起使用时,JPA 确实是一种替代方法。例如,IDEA 将在字符串中全面完成 JPA 查询

回答by Lukas Eder

You won't find an equivalent of LINQ unless you use the javaccto create your own equivalent.

除非您使用javacc创建自己的等价物,否则您将找不到 LINQ的等价物。

Until that day when someone finds a viable way to do so, there are some good alternatives, such as

直到有一天有人找到可行的方法来做到这一点之前,还有一些不错的选择,例如

回答by Safin Ahmed

For LINQ (LINQ to Objects to be more accurate) you can use Streams starting from Java 8

对于 LINQ(LINQ to Objects 更准确),您可以使用从 Java 8 开始的 Streams

This doesn't work for databases however, only for internal objects like Collections and Lists

但是,这不适用于数据库,仅适用于集合和列表等内部对象

It is really powerfull, but not as complete as LINQ (in my opinion)

它真的很强大,但不如 LINQ 完整(在我看来)

Check out this tutorial - http://www.oracle.com/technetwork/articles/java/ma14-java-se-8-streams-2177646.html

查看本教程 - http://www.oracle.com/technetwork/articles/java/ma14-java-se-8-streams-2177646.html

As for Entity Framework there is nothing quite as powerful that I have found yet, but haven't tried all the solutions provided in the other answers

至于实体框架,我还没有找到比这更强大的东西,但还没有尝试其他答案中提供的所有解决方案