LINQ: Reconciling objects, relations and XML in the .NET framework
LINQ: Reconciling objects, relations and XML in the .NET framework
Linq:统一Microsoft .Net Framework中的对象、事务日志以及Xml
作者:不译
Erik Meijer
Microsoft Corporation
Redmond, USA
emeijer@microsoft.com
Brian Beckman
Microsoft Corporation
Redmond, USA
bbeckman@microsoft.com
Gavin Bierman
Microsoft Research
Cambridge, UK
gmb@microsoft.com
Introduction Many software applications today need to
handle data from different data models; typically objects
from the host programming language along with the re-
lational and XML data. The ROX impedance mismatch
makes programs awkward to write and hard to maintain.
The .NET Language-Integrated Query (LINQ) framework,
proposed for the next release of the .NET framework, ap-
proaches this problem by dening a design pattern of general-
purpose standard query operators for traversal, lter, and
projection. Based on this pattern, any .NET language can
dene special query comprehension syntax that is subse-
quently compiled into these standard operators (our code
examples are in VB).
引言:当今的许多应用软件都要通过不同的数据Model来操作数据;其中典型的编程方式就是关系数据库与XML文档(数据)之间的协作。关系与XML的互阻导致了错误的产生我们称之为[阻抗失谐],这种编程方式使程序难以更改并且实现起来较为复杂。(ROX 我感觉应该是relational of XML)被建议整合在.net framework 下一版本(.net 3.5已发布)中的.net 语言集成查询框架(LINQ)以一种内置的合乎设计模式的操作符定义来进行数据的访问,过滤和发送操作。基于这种模式,任何一种.net下的编程语言都可以使用这些操作符定义一个编译器可以编译的查询语句语法(本文章的示例都是VB.net的)。
Besides the general query operators, the LINQ framework
also denes two domain-specic APIs that work over XML
(XLinq) and relational data (DLinq) respectively. The oper-
ators over XML use a lightweight and easy-to-use in-memory
XML representation to provide XQuery-style expressiveness
in the host programming language. The operators over re-
lational data provide a simple OR mapping by leveraging
remotable queries that are executed directly in the back-end
relational store.
此外,一般的查询操作符,Linq框架中分别定义了操作XML的XLINQ和操作关系数据库的DLINQ两种Apis。XML下的操作符使用一个轻量级的易用的以XQuery-style形式体现出来的内存运行的编程语句。这些操作符提供了一个简单的对象关系映射作为直接的关系存储的体现。
Standard query operators It is well known that col-
lections can be modeled as monoids and queries over them
as monoid homomorphisms. Analogously, LINQ denes an
API pattern that enables querying of any collection or .NET
array. This query operator set includes familiar constructs
such as ltering (where), mapping (select), monadic bind
(selectMany), sorting (orderby) and partitioning (groupBy).
These query operators can be freely composed to form
rich queries; e.g. the following code returns the name and
phone numbers of customers from Seattle ordered by their
age:
众所周知标准查询操作符可以有各种灵活多变的形式,与此类似的,LINQ定义了一个API模式的查询方式,可以查询任意的泛型或。NET数组。查询操作符集包含了一些大家熟悉的过虑操作符(where),映射(Select),单一绑定(selectMany),排序(orderBy)以及分类查询(groupBy),这些查询操作符可以以查询形式轻松组建。以下面这段代码为例,从Seattle中查询客户的姓名和电话,前按用户年龄排序:
Dim cs = From c In Customers
Where c.Address.City = "Seattle"
Order By c.Age
Select c.Name, c.Phone
XLinq The LINQ framework also includes a new, modern,
lightweight XML API that makes it simple to program XML
and integrates smoothly with the standard query operators
of LINQ.
XLinq Linq 框架也包含一个与时俱进的轻量级的类似于编写XML来综合运用标准查询请用操作Linq的XML API 。
In XLinq, nodes are rst-class citizens that can be passed
around independently of an enclosing document. Nested el-
ements are constructed in an expression-oriented fashion.
Elements and attributes are accessed uniformly using famil-
iar XPath axis-style methods, while namespace handling is
simplied using the notion of universal names.
在XLinq中,结点是 类优先的 封闭标签文档构成的统一结构。层叠结点则由一个样式向导创建。当命名空间引用相应的抽象类库时,其结点与属性可以像XPATH一样统一访问方法 。
In addition to the XLinq API, VB 9.0 adds XML liter-
als with full namespace support. A variant of the previous
query that returns each customer as XML simply uses the
following expression in the select clause:
附加的XLinq Api中VB 2008 (9.0)和XML有着全面的命名空间支持,从前一个变量可以用以下方式采用XML简单地遍历查询用户信息。
<Customer Name=<%= c.Name %>>
<Phone><%= c.Phone %></Phone>
</Customer>
DLinq The LINQ framework also provides infrastruc-
ture for managing relational data as objects. It leverages
the ability of LINQ to provide intensional representations of
delegates as code trees by translating language-integrated
queries into SQL for execution by the database, and then
translating the resulting table into objects. The DLinq in-
frastructure maintains an identity cache and performs change
Tracking.
DLinqLinq类库也支持关系数据库映射为对象的方法。它与SQL及中间语言高度内聚,可以将文档树与对象互相转换,DLinq可以缓存数据和进行事务跟踪。
The mapping between database tables and in-memory ob-
jects is done via custom attributes (annotations) such as
<Association(OtherKey="CustomerID")> to indicate foreign
key associations and <Column(Id=true)> to indicate pri-
mary keys.
数据库表和内存对象之间的映射关系通过类似<Association(OtherKey="CustomerID")>的声明式编程方法来实现,一个外键和一个主键用类似 <Column(Id=true)>的声明编程方式来表示。
In the following query, the navigation between the cus-
tomer and address objects will automatically be compiled
into the appropriate joins of the underlying tables.
下面的这段查询代码,表示了用户与地址对象将自动编译并指向相应的表。
Dim db = new MyDataBase("...");
Dim cs = From c In db.Customers
Where c.Address.City == "Seattle"
Select c.Name, c.Address
As soon as objects are loaded into the data context, either
by retrieving them through a query or by constructing new
objects and inserting them, DLinq tracks all the changes
and transmits these objects back to the database when re-
quested, automatically generating and executing the appro-
priate SQL commands.
当对象被上下文使用时,无论是通过一个查询来检索还是要构造一个新对象来进行插入。DLinq总会跟踪所有变化,并将它们在查询时用SQL语句传回数据库。
http://msdn.microsoft.com/netframework/future/linq/
1
LINQ: Reconciling objects, relations and XML in the .NET framework相关推荐
- Does the “LINQ to Objects” provider have built-in performance optimization?
让我们从基础开始,可能会重复一些你已经知道的信息.在LINQ性能优化中最重要的一点,当然是延迟执行.那便意味着当你声明一个变量并分配给它一个查询字符串,其查询字符串并没有立即执行 // Query i ...
- 从LINQ开始之LINQ to Objects(上)
LINQ概述 LINQ,语言集成查询(Language Integrated Query),它允许使用C#或VB代码以查询数据库相同的方式来操作不同的数据源. LINQ体系结构 从上图可以看出,LIN ...
- [翻译]“LINQ to Objects”提供程序是否内置性能优化?
原文来自Alexandra Rusina在CSharpFAQ的:Does the "LINQ to Objects" provider have built-in performa ...
- 【翻译】Pro LINQ Language Integrated Query in C# 2008 -- 第三章 (LINQ TO Objects) 第一节
LINQ到Objects LINQ到Objects介绍 示例 3-1. 一个LINQ到Objects查询的示例. string[] presidents = { "Adams&quo ...
- 从LINQ开始之LINQ to Objects(下)
前言 上一篇<从LINQ开始之LINQ to Objects(上)>主要介绍了LINQ的体系结构.基本语法以及LINQ to Objects中标准查询操作符的使用方法. 本篇则主要讨论LI ...
- 基于Visual Studio2010讲解LINQ读出数据库数据生成XML
LINQ to XML 是一种启用了 LINQ 的内存 XML 编程接口,使用它,可以在 .NET Framework 编程语言中处理 XML. LINQ to XML 最重要的优势是它与 Lang ...
- 查询表达式和LINQ to Objects
查询表达式实际上是由编译器"预处理"为"普通"的C#代码,接着以完全普通的方式进行编译.这种巧妙的发式将查询集合到了语言中,而无须把语义改得乱七八糟 LINQ的 ...
- 自己动手重新实现LINQ to Objects: 9 - SelectMany
本文翻译自Jon Skeet的系列博文"Edulinq". 本篇原文地址: http://msmvps.com/blogs/jon_skeet/archive/2010/12/27 ...
- Linq to objects示例
与linq to sql类似,所有继承了IEnumerable的类型均可使用LINQ,如下string[]数组基类为Array,而Array实现了IEnumerable,所以也可使用linq stat ...
最新文章
- CactiEz 无法登陆 、重启不画图处理
- 基础篇:7.Content provider与Content Resolver实现数据共享
- 可视化:中国地图 python/ geopandas/ echarts
- 【转】Azure Messaging-ServiceBus Messaging消息队列技术系列2-编程SDK入门
- WebAssembly 技术汇总
- 前端笔记之JavaScript(十二)缓冲公式检测设备Data日期
- 第八章,作业(网络电视精灵)
- C# USING ADO.NET
- java 数据转成xml_java转换CSV文件生成xml格式数据
- 干掉visio,这个画图神器太香了
- 3.4 主存储器与CPU的连接———存储器容量的扩充
- python批量保存网页为pdf_在chrome中自动打印/保存网页为pdf - python 3.6
- java 类型通配符_通配符类型
- 算法-点线关系-投影在线段上各点距离最大
- 小型微型计算机投稿流程,小型微型计算机系统
- vue项目整合ckplayer
- 科沃斯机器人招股_603486_科沃斯招股说明书.pdf
- 分类性能度量指标:准确性(AC)、敏感性(SE)、特异性(SP)、F1评分、ROC曲线、PR(Precision-Recall)曲线、AUC曲线,混淆曲线
- perl python文本处理_Perl 调用R分词进行文本数据分析
- Mac Catalina系统关闭/打开开机duang音效
热门文章
- 刚学Tableau的小白也可以作出美观大气的数据图表
- 小米9pro textView不设置颜色不显示_小米万象息屏2.0内测开启,新增小组件功能和新息屏...
- python time模块的strftime函数
- 商业价值深度报道 iPad降临昭示苹果的未来
- 【手势识别】笔记本摄像头实时手势识别,同理可进行其它目标检测
- 同源政策(same-origin policy)
- 真香定律?继堡垒之夜之后,方舟:生存进化也要出国服手游啦
- uos系统能做服务器吗,国产操作系统UOS可以用PS,还可以玩英雄联盟?
- 速卖通大卖不会告诉你的技巧,学会这招出单很简单
- 封装弹出框组件 vue3