[转]LINQ会为我们带来什么?

What LINQ will offer
LINQ 会为我们带来什么?
.NET's new query operators.
.Net 的新型查询操作
By David Rhys, Techworld
作者: David Phys TechWorld
Translated By Joey Yin CNBlogs.com
译者: Joey Yin Cnblogs.com
According to C#’s architect Anders Hejlsberg, there's an "impedance mismatch" between most programming languages and the database.
根据 C# 架构师 Anders Hejlsberg 的说法,在大多数编程语言和数据库之间,有一个“阻抗失谐”的问题。

What this means is that programming is all about procedural processing and how business (and other logic) works, while database access (at least in the relational database world) is all about declarations of what data you want (roughly, "SELECT A FROM B WHERE X=Y"), regardless of how you'll get it and what table it’s in. So, you issue simple declarative queries against a database; and when you get the data back into your program, in memory, you process it entirely differently. Wouldn't it be nice if there was a simple declarative language built into, say, C# or Visual Basic (Microsoft seems to think that these are the typical developer's primary programming languages, although no doubt some would disagree)?
阻抗失谐意味着数据库(至少对于关系型数据库)是对需要“什么样”的数据的一种定义(简单说来,就是 SELECT A FROM B WHERE X=Y 这种东东),而编程则全部是关于“怎样”通过程序处理业务和逻辑的工作,而不关心你怎样获取他,数据存储在哪个表里面。因此,我们依靠数据库来提供简单的查询接口,当你取出数据到你的应用中时,我们在内存中使用完全不同的方法来处理这些数据。所以,如果能够有一种简单的查询语言内嵌到我们的编程语言中,例如 c#, vb (这是微软认为的多数开发者首选的编程语言,当然,很多反对者并不这么认为),那将是一个多么美好的世界!
This is what LINQ (Language INtegrated Query) will deliver, on the .NET platform. It's set of general-purpose declarative query operators that allow traversal, filter, and projection operations to be applied to any IEnumerable-based information source. LINQ queries read a bit like SQL but can be applied to non-relational datasources such as XML data and so on.
这就是 LINQ( 语言集成查询 ) .NET 平台上所要做的。他是一个多用途的查询操作集,允许在实现了 Ienumerable 接口的任何对象上进行数据的访问,过滤和发送操作。 LINQ 查询有一点像 SQL 语句,但是它可以应用于非关系型数据库的数据源中,例如 XML 等等。
The LINQ query language uses "lambda expressions", an idea originating in functional programming languages such as LISP - a lambda expression defines an unnamed function (and lambda expressions will also be a feature of the next C++ standard). In LINQ, lambdas are passed as arguments to its operators (such as Where, OrderBy, and Select) - you can also use named methods or anonymous methods similarly - and are fragments of code much like delegates, which act as filters.
LINQ 查询使用 Lambda 表达式,这是一个源于 Functional Programming 语言(例如 LISP )的新点子。 Lambda 表达式可以定义一个匿名的方法( Lambda 表达式也会同样成为下一个版本的 C++ 标准的一个新功能)。在 LINQ 查询中, Lambda 表达式被当作参数传递给操作者(例如 Where, OrderBy Select ),当然你也可以使用实名方法或者匿名方法,当然这种使用更像是在使用代理了。
LINQ also defines a distinguished type, Expression (in the System.Expressions namespace), which means that you want to use an "expression tree" (an efficient in-memory data representation of a lambda expression) instead of a traditional method body - this may make the structure of the expression clearer.
LINQ 定义了一个卓越的类型( distinguished type )(在 System.Expressions 命名空间里),这意味着你需要使用一个“表达式树” ( 表达式树是一种更高效的表现形式,用以描述 lambda 表达式在内存中的数据 ) 来取代传统的方法体,这将使得表达式的结构更加清晰。
Another idea LINQ borrows, this time from dynamic languages, is the idea of "extension methods". These allow third parties to add new methods to the public contract of a type without stopping individual type authors from providing specialised method implementations.
LINQ 带来的另外一个概念“扩展方法”来源于动态语言。它允许第三方可以通过附加的方法扩展已存在的类型和构造类型。
One key feature of LINQ is its implicit support for SQL (DLinq) and XML (XLinq) integration, and this will assist full-blown object relational mapping products, as these can now take advantage of inbuilt language support. However, one possible issue is that it doesn't (as far as I can see) have the solid foundation in set theory that a query language based on a pukka relational algebra has (see Chris Date, “Database in Depth”, O’Reilly, ISBN 0-596-10012-4, for what this means). It may be possible for a programmer to confuse the quality of data sourced from a relational database (where integrity is enforced by the RDBMS – Relational DataBase Management System - itself and can largely be relied on) and data sourced from, say, an XML data store (where it isn't and can't be). In practice, since most RDBMSs (and the SQL language itself) compromise hugely with the purist relational model and therefore can't really claim the benefits from following it, this may not matter – LINQ is no worse than everything else (and relational algebra may be too hard for many people anyway). However, some people (myself included) think the loss of the formal rigor associated with the relational theory is to be regretted – although LINQ, in itself, doesn’t force any RDBMS to abandon relational theory, of course.
LINQ 的一个主要的功能是它对 SQL XML 都提供强大的支持(分别通过 DLing XLing )。这会极大的促进 ORMapping 技术的发展,因为现在可以利用内嵌语言了。但是,一个可能的情况是它在集合处理领域还缺乏像关系型数据库那样坚实的基础。这可能会使程序员被来源于关系型数据库(由关系型数据库自身保证其完整性)和其他数据源(例如 XML ,无法确立严格约束)的数据良莠不齐的品质搞糊涂。在实践中,许多关系型数据库(以及 SQL 语言本身)都没有非常严格地遵循关系型模型的理论,所以还不能简单声称这样做有多么重要。这是不公平的—— LINQ 不比其他这些差(关系代数对普通人来说,实在是太难了)。当然,尽管 LINQ 自己当然没有强迫任何关系型数据库放弃关系理论,但是很多人(包括我在内)都会为这种过分苛刻的联合感到遗憾。
In terms of the evolution of programming languages, LINQ represents a fusion of a typical OO language (C#) with ideas taken from modern dynamic languages such as Ruby and functional languages such as Lisp. It’s a thoroughly interesting idea and its availability probably will make C# a technical advance on Java, for a time at least. However, whether it actually delivers better (more powerful, more reliable and more maintainable) applications - which is presumably what it's all about at bottom for the companies employing .NET developers - depends on how C# and VB programmers take to such concepts as lambda expressions, expression trees and declarative programming.
从编程语言的演变来讲, LINQ 代表的更多的是经典的面向对象语言( C# )和现代动态语言( Ruby )以及函数式语言( Lisp )的一种融合。它非常有趣而且可能会使 C# 在技术上暂时领先 Java 。无论如何,它最终能否帮助我们开发出更高质量(更强大,更可靠以及更可维护的)的应用——这些大概是所有公司在招聘 .NET 程序员时的最起码要求了——最终还是要取决于:我们的 C# VB 程序员是否喜欢这些概念: Lambda 表达式,表达式树和 宣告式编程。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值