Dev221 VB中的LINQ:未来之路.

Slides:



Advertisements
Similar presentations
Which TV program is the video? 中国达人秀 China’s Got Talent 选秀节目 talent show talent n. 天资;天赋.
Advertisements

allow v. wrong adj. What’s wrong? midnight n. look through guess v. deal n. big deal work out 允许;准许 有毛病;错误的 哪儿不舒服? 午夜;子夜 快速查看;浏览 猜测;估计 协议;交易 重要的事.
Presented By: 王信傑 Ricky Wang Date:2010/10/6
10-1 資料庫管理系統簡介 10-2 關聯式資料模式和查詢語言 10-3 Access 簡介 10-4 XML 簡介
王书贵 资深分析师 CCW Research 计世资讯
深市协助执法及证券查询业务介绍 客户服务部 China Securities Depository
专题八 书面表达.
Database Architecture, not only DBA
抱怨處理技巧 高雄捷運公司 公共事務處 胡宜萍 安全 ‧ 便捷 ‧舒適 ‧ 可靠
張書源 Microsoft MVP MCT 趨勢科技 技術經理 網酷科技 資深顧問 集英信誠 資深顧問
控制流程實作 胡百敬 精誠公司恆逸資訊 二○一七年三月十九日
資料庫設計 Database Design.
——打造科技金融升级版 中国建设银行顺德分行 2015年6月.
摘要的开头: The passage mainly tells us sth.
云实践引导产业升级 沈寓实 博士 教授 MBA 中国云体系产业创新战略联盟秘书长 微软云计算中国区总监 WinHEC 2015
Homework 4 an innovative design process model TEAM 7
Unit 4 I used to be afraid of the dark.
關聯式資料庫.
DEV323 .NET架构:全球化思想! 定制各种文化及国际数据
BizTalk Server 2004.
解振宇 客户技术经理 客户售前技术部 微软中国有限公司广州办事处
Mobile & Embedded DevCon 2005 朱敏博士 微软有限公司
Windows Mobile 轻松接轨GPS
簡易 Visual Studio 2010 C++ 使用手冊
从UNIX到Windows的 电信软件移植实践
卢斌 Software Development Engineer Microsoft Corporation
HOW TO ACE -- THE IELTS SPEAKING TEST
第16章 VB.NET物件導向與.NET Framework
BizTalk Server 2004.
第20章 LINQ 資料查詢技術 注意: 本投影片僅供本書上課教師使用,非經同意請勿上網轉載或拷貝.
第4章(2) 空间数据库 —关系数据库 北京建筑工程学院 王文宇.
OFC351 利用Office System开发复杂的商务解决方案 架构、模式、场景
iSlide® PowerPoint standard template.
This Is English 3 双向视频文稿.
微软新一代云计算 面向企业的 Office 365 客户培训大纲
客户服务 询盘惯例.
第4章(1) 空间数据库 —数据库理论基础 北京建筑工程学院 王文宇.
Lesson 44:Popular Sayings
簡易 Visual Studio 2005 C++ 使用手冊
基于课程标准的校本课程教学研究 乐清中学 赵海霞.
Microsoft SQL Server 2008 報表服務_設計
IBM SWG Overall Introduction
利用 ASP.NET MVC 提升您的 Web 應用程式
資料結構 Data Structures Fall 2006, 95學年第一學期 Instructor : 陳宗正.


OFC321 InfoPath在企业解决方案中应用的最佳实践
Guide to a successful PowerPoint design – simple is best
SQL Server Mobile 2005 程序开发(三)
虚 拟 仪 器 virtual instrument
Unit 7 Lesson 20 九中分校 刘秀芬.
模式与实践:Windows Mobile 5.0应用程序架构
DEV342 Visual Basic 2005: 应用程序框架 和高级语言特性
TEEN CHALLENGE Next Steps 核心价值观总结 CORE VALUES 青年挑战核心价值观
Microsoft Visual C# 2005: IDE 技巧与诀窍
5/5/2019 7:06 PM 两跨框架梁截面配筋图的绘制 © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may.
SQL Server Mobile 2005 程序开发(二)
冀教版 九年级  Look into Science!.
计算机问题求解 – 论题1-5 - 数据与数据结构 2018年10月16日.
M; Well, let me check again with Jane
Create and Use the Authorization Objects in ABAP
Unit 1 How do you study for a test?
5/15/2019 姓名: 公司名称: 云赛空间BP模板 Now let’s take a look at who we are, what we’re doing and why we’re doing it in China... This is an image of a technology.
怎樣把同一評估 給與在不同班級的學生 How to administer the Same assessment to students from Different classes and groups.
Arguments to the main Function and Final Project
蔺华 ISV开发合作经理 平台及开发技术部 微软(中国)有限公司
MGT 213 System Management Server的昨天,今天和明天
高擴充高穩定高安全 企業級資料管理平台 Report Builder概論 錢曉明 資策會 資深講師 台灣微軟 資深講師.
Windows Workflow Foundation CON 230
When using opening and closing presentation slides, use the masterbrand logo at the correct size and in the right position. This slide meets both needs.
Presentation transcript:

Dev221 VB中的LINQ:未来之路

课程内容概述 LINQ的字面含义是“语言集成的查询”- Language INtegrated Query。它是下一版Visual Studio的功能重点之一。它扩展了VB,让大家可以使用类似SQL的语言来操作多个数据源,例如Object Collection, XML, Dataset以及Database。

课程内容安排 LINQ项目概述 基于对象数据的LINQ 基于SQL的LINQ(DLinq) 基于XML的LINQ(XLinq)

Visual Basic 9.0 简化查询数据 便于使用XML 简化性、一致性&提高生产效率 在VB语言中集成查询操作 2019年1月16日7时32分 Visual Basic 9.0 简化查询数据 在VB语言中集成查询操作 对对象数据、关系型数据和XML数据建立统一的查询 便于使用XML 快速生成XML文档 简化性、一致性&提高生产效率 Visual Basic 9.0 Goals Visual Basic 2005 is going to be a really exciting release with tons of great features, but as we look beyond November, we’ve been thinking about how we can make a major improvements in the ease and speed with which people program in Visual Basic. Specifically, we’ve been looking at two areas for the next major release. (Click.) We’ve been thinking about how we can simplify querying data. Today, when you query data, you tend to run into two problems. One problem is that you often have to end up writing a lot of code over and over and over again to do what are relatively simple and straightforward operations – sort, filter, project, etc. The other problem is that you frequently have to deal with a huge amount of friction between the .NET type system and other type systems such as SQL and XML that make querying those types of data more difficult than it should be. Finally, we’ve been thinking about how we can make it easier and simpler to work with XML. With the increasingly central role that XML plays in the programming world, producing XML is becoming more and more a common programming task, and one that still requires too much boilerplate code. What we’re going to talk about today, then, are some of the cool solutions that we’ve come up with for these three problem areas that we think will make programming in Visual Basic (and C#) radically easier and faster. 4 ©2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Language Integrated Query 2019年1月16日7时32分 Language Integrated Query Demo: Basic Language Integrated Query over In-Memory objects 5 ©2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

LINQ项目 .NET Language Integrated Query VB C# Others… 2019年1月16日7时32分 LINQ项目 VB C# Others… .NET Language Integrated Query Standard Query Operators DLinq (ADO.NET) XLinq (System.XML) Project LINQ Language integrated query is actually a platform-wide effort. The core is a set of API patterns that define how an object exposes query operations. Languages build features on top of those APIs. Components expose query services through those APIs. Both sides are fully documented and extensible. SQL Objects <book> <title/> <author/> <year/> <price/> </book> XML 6 ©2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

LINQ的创新点 对对象数据、关系型数据和XML数据建立统一的 查询和转换 VB查询语法类似于SQL和Xquery 2019年1月16日7时32分 LINQ的创新点 对对象数据、关系型数据和XML数据建立统一的 查询和转换 VB查询语法类似于SQL和Xquery 查询的类型检查、intellisense和代码重构 语言/API设计具有可扩展性 7 ©2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

语言的创新点 Implicitly typed locals 隐式类型的局部变量 Extension methods Extension方法 2019年1月16日7时32分 语言的创新点 Dim x = 5 Implicitly typed locals 隐式类型的局部变量 Extension methods Extension方法 Inline functions 内联函数 Object initializers 对象初始值 Anonymous types 匿名类型 Query expressions 查询表达式 <Extension> Sub Randomize(col As Collection) Function(c) c.Name New Point { x := 1, y := 2 } New { c.Name, c.Phone } 100% backwards compatible From … Where … Select 8 ©2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

查询语法 Project Select <expr> Filter Where <expr> Test 2019年1月16日7时32分 查询语法 Project Select <expr> Filter Where <expr> Test Any(<expr>), All(<expr>) Join <expr> Join <expr> On <expr> Group Group By <expr> Aggregate Count(<expr>), Sum(<expr>), Min(<expr>), Max(<expr>), Avg(<expr>) Partition Top <expr> Set Distinct, Union, Intersect, Except Order Order By <expr> Convert ToArray, ToList, ToBindingList Cast As <typename>, OfType(Of T) 9 ©2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

关系型数据的DLinq 当前访问数据的方法 SqlConnection c = new SqlConnection(…); 2019年1月16日7时32分 关系型数据的DLinq 当前访问数据的方法 SqlConnection c = new SqlConnection(…); c.Open(); SqlCommand cmd = new SqlCommand( @"SELECT c.Name, c.Phone FROM Customers c WHERE c.City = @p0"); cmd.Parameters["@p0"] = "London"; DataReader dr = c.Execute(cmd); while (dr.Read()) { string name = r.GetString(0); string phone = r.GetString(1); DateTime date = r.GetDateTime(2); } r.Close(); Queries in quotes Loosely bound arguments Loosely typed result sets Goal: show how powerful, but cumbersome ADO.NET is today No compile time checks 10 ©2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

关系型数据的DLinq 使用DLing访问数据 Classes describe data Public Class Customer … 2019年1月16日7时32分 关系型数据的DLinq 使用DLing访问数据 Classes describe data Public Class Customer … Public Class Northwind Inherits DataContext Public Property Customers As Table(Of Customer) … End Class Tables are like collections Strongly typed connection Dim db As New Northwind(…) Dim contacts = _ From c in db.Customers _ Where c.City = "London" Select c.Name, c.Phone Goal: showcase DLinq simplicity and how it solves previously identified problems Integrated query syntax Strongly typed results 11 ©2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

编写DLinq应用程序 2019年1月16日7时32分 Part I Goal: showcase the designer and the power of the query language Remove object model Create new DLinq designer object Drag and drop Customer, Order, Order detail and show properties Re-execute same query Query for both customers and nested orders (it is better than SQL!!) Part II Goal: showcase Joins (how to ask questions about classes that don’t have an explicit relationship) Drag and drop Supplier Join Customer/Supplier over Country, return c.CustomerID, c.Country, Sups.Count() Execute Add a where clause Part IV Goal: show the debugging of the SQL query Place a breakpoint Use the DLinq visualizer to inspect the SQL query In the visualizer Change the select to get City 12 ©2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

关系型数据的DLinq 使用语言中的数据访问 影射 其它 影射tables/rows 到类/对象 2019年1月16日7时32分 关系型数据的DLinq 使用语言中的数据访问 影射tables/rows 到类/对象 基于ADO.NET 以及.NET Transactions 影射 工具生成或手工编写 其它 可以使用存储过程 支持其实数据库 (需插件) Goal: summary of demo 13 ©2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

XML数据的XLinq 当前XML编程方式 Imperative model Dim doc As New XmlDocument() 2019年1月16日7时32分 XML数据的XLinq 当前XML编程方式 Imperative model Dim doc As New XmlDocument() Dim contacts As XMLElement = doc.CreateElement("contacts") For Each Dim c in Customers If (c.Country = "USA") Dim e As XMLElement = doc.CreateElement("contact") Dim name As XMLElement = doc.CreateElement("name") name.InnerText = c.CompanyName e.AppendChild(name) Dim phone As XMLElement = doc.CreateElement("phone") phone.InnerText = c.Phone e.AppendChild(phone) contacts.AppendChild(e) End If Next doc.AppendChild(contacts) Document centric No integrated queries Memory intensive Goal: highlight imperative DOM model <contacts> <contact> <name>Great Lakes Food</name> <phone>(503) 555-7123</phone> </contact> … </contacts> 14 ©2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

XML数据的XLinq 使用XLinq进行编程 Declarative model 2019年1月16日7时32分 XML数据的XLinq 使用XLinq进行编程 Declarative model Dim contacts As New XElement("contacts", _ From c in customers _ Where c.Country = "USA“ _ Select New XElement("contact", _ new XElement("name", c.CompanyName), _ new XElement("phone", c.Phone) _ ) Element centric Integrated queries Goal: highlight declarative DOM model Smaller and faster 15 ©2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Expression holes for computed values 2019年1月16日7时32分 在Visual Basic中集成XML 利用XLinq在VB中进行XML编程 Infers XLinq XElement Dim contacts = _ <contacts> <%= _ From c In customers _ Where c.Country = "USA" _ Select <contact> <name><%= c.CompanyName %></name> <phone><%= c.Phone %></phone> </contact> _ %> </contacts> No conceptual barrier True to VB’s design principals: - Best practices by default – Translates to XLinq - Intuitive – No conceptual barrier between Object Model and XML you intend to write - Productive – Full IDE integration, colorization, Intellisense, - Pragmatic – Expression holes for inserting captured values Expression holes for computed values 16 ©2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

2019年1月16日7时32分 使用XLinq Part I Goal: show the declarative simplicity of creating an XML doc Iteratively create a simple XML doc by using the constructor semantic (i.e. Grandaddy, Daddy, Son) Part II Goal: show how working across data domain is greatly simplified with LINQ Create and XML doc that gets filled by a query that goes against northwind Part III Goal: showcase VB XML integration Show XElement Show XML syntax Show cut and paste Show accessing member 17 ©2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

XML数据的XLinq 与语言集成的XML查询 具有XPath / XQuery的表达能力 利用DOM的经验 元素为中心,而不是文档为中心 2019年1月16日7时32分 XML数据的XLinq 与语言集成的XML查询 具有XPath / XQuery的表达能力 将VB或C#作为编程语言 XML和代码之间无任何概念上的障碍 利用DOM的经验 元素为中心,而不是文档为中心 对称的元素/属性API 功能性的构造 文本结点仅仅是字符串 简化的XML命名空间支持 更快且更小 Goal: summary of demo 18 ©2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

LINQ项目 .NET的Language Integrated Query 标准查询操作 DLinq XLinq 2019年1月16日7时32分 LINQ项目 .NET的Language Integrated Query 在VB9.0和C#3.0的语言中具有内建的查询语法 标准查询操作 对任意.NET集合的类似SQL的查询 DLinq 可查询的数据访问框架 XLinq 可查询的XML DOM, 并且更小, 更快 Goal: this is what you should remember of the presentation 19 ©2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

总结 Language Integrated Query Language 的优点 更多信息 2019年1月16日7时32分 总结 Language Integrated Query Language 的优点 对于对象数据,关系型数据和XML数据的统一查询 查询的类型 在VB和C#中的类似SQL和XQuery的查询 仅支持.NET平台 更多信息 主页: http://msdn.microsoft.com/netframework/future/linq/ 可下载Customer Tech Previews版本! Contact: Juliapa@microsoft.com 我们需要您的反馈意见 20 ©2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

© 2005 Microsoft Corporation. All rights reserved. 2019年1月16日7时32分 © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary. 21 ©2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

XML Member Binding XML成员绑定 Late binding covers all XML axes 延后绑定所有的XML axes Dim cosmos As XElement = GetCurrentLinkCosmos().Root Dim ver As Double = CDbl(cosmos.Attribute("version")) Dim item As XElement = First(cosmos.Descendents("item")) Dim created As Date = CDate(item.Element("linkcreated“)) Attributes Descendents Elements Dim cosmos As XElement = GetCurrentLinkCosmos().Root Dim ver As Double = CDbl(cosmos.@version) Dim item As XElement = cosmos…<item>.Value Dim created As Date = CDate(item.<linkcreated>)

XML Literals XML Literals 2019年1月16日7时32分 XML Literals XML Literals Shorthand for object creation 编写对象生成代码 Dim emp = _ <employee> <name>Joe</name> <age>28</age> <department id="432"> <deptname>Engineering</deptname> </department> </employee> Dim emp = _ New XElement("employee", _ New XElement("name", "Joe"), _ New XElement("age", 28), _ New XElement("department", _ New XElement("name", "Engineering"), _ New XAttribute("id", 432))) 24 ©2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Deferred Query Execution 向后优先解析的查询表达式 2019年1月16日7时32分 Deferred Query Execution 向后优先解析的查询表达式 Dim custs() As Customer = SampleData.GetCustomers() Dim q = Select c.City From c In custs Where c.State = "WA" Dim q = custs.Where(AddressOf _Filter1).Select(AddressOf _Project1) Dim names() As String = q.ToArray() custs Phone Name ID names AddressOf _Filter1 Where Select AddressOf _Project1 Deferred Query Execution 25 ©2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Expression Trees 表达式树 Defer code interpretation 向后优先解析的代码 System.Query.Expression(Of T) where T is a delegate type Dim f As Predicate(Of Customer) = (c) c.State = "CA" Dim e As Expression(Of Predicate(Of Customer)) = (c) c.State = "CA" Dim e As Expression(Of Predicate(Of Customer)) = _ New Expression(Of Predicate(Of Customer))( New BinaryExpression(ExpressionType.EQ, New PropertyExpression( New ParameterExpression(0), GetType(Customer).GetProperty("State") ), New ConstantExpression("CA") )

Extension Methods 扩展模型 Extend existing types with new methods 使用新方法扩展存在的类型 Extension IntArrExtensions To Integer() Function Sort() As Integer() … End Function ReadOnly Property Sum() As Integer Get End Get End Property End Extension obj.Foo(x, y)  XXX.Foo(obj, x, y) Imports IntegerArrExtensions Dim values() As Integer = GetValues() Console.WriteLine(IntegerArrExtensions.Sum(IntegerExtensions.Sort(values)) Dim values() As Integer = GetValues() Console.WriteLine(values.Sort().Sum())

Simple Type Inference 简单类型引用 2019年1月16日7时32分 Simple Type Inference 简单类型引用 Variable type inferred from initializer 由初始值推断的变量类型 Integer All types are Object! String Dim x = 5 Dim s = "Hello" Dim d = 1.0 Dim numbers = New Integer() {1, 2, 3} Dim orders = new Dictionary(Of Integer, Order)() Double Add at the end that type inferencing has some compat implicaitons... But we think it's okay. 28 ©2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Add link to external Community website List top 3 newsgroups related to this slide 1 2 3 Advise when your next chat is Next user group meeting you will be at Add Other related 3rd party sites

填反馈表

讲师的Chalk Talk和其他Session

与本次主题有关的Session和活动