Discuz!NT
欢迎 游客 , 注册 | 登录 | 会员 | 界面 | 简洁版本 | 在线 | 帮助
商都网教育宝典宝库

发表新主题 回复该主题
本主题被查看1205次, 共1个帖子, 1页, 当前为第1页     选择页数: 1      跳转到第   上一主题   下一主题
标题: Linq to Sql: 集成数据库语言查询
张小峰
超级版主
UID: 14
来自:
精华: 4
积分: 313
帖子: 285
注册: 2007-8-23 10:27:00
状态: 离线
威望: 8.00
金钱: 75.55 元
只看楼主 2007-08-23 10:53
Linq to Sql: 集成数据库语言查询
原文声明:
Information in this document is subject to change without notice. The example companies, organizations, products, people, and events depicted herein are fictitious. No association with any real company, organization, product, person or event is intended or should be inferred. Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation.


Microsoft may have patents, patent applications, trademarked, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property.


© 2005 Microsoft Corporation. All rights reserved.


Microsoft, MS-DOS, MS, Windows, Windows NT, MSDN, Active Directory, BizTalk, Sql Server, SharePoint, Outlook, PowerPoint, FrontPage, Visual Basic, Visual C++, Visual J++, Visual InterDev, Visual SourceSafe, Visual C#, Visual J#,  and Visual Studio are either registered trademarks or trademarks of Microsoft Corporation in the U.S.A. and/or other countries.


Other product and company names herein may be the trademarks of their respective owners.


译者声明:
译者: 随风流月(http://cangying.cnblogs.com/)
鸣谢: 装配脑袋(http://ninputer.cnblogs.com/)
基于 Creative Commons 署名-相同方式共享 2.5 中国大陆 License 发布
将依照翻译之进程,同步更新于鄙人 Blog 上,最终将发布 doc 文档。图片暂时无法贴于此处。同时,鉴于鄙人英文水平不佳,若有错谬,敬请直言,感激涕零。



实验营 1: Linq To Sql: 集成数据库语言查询
这个实验营将向您清晰地描绘借助于 Linq to Sql,Linq 项目对于关系型数据存取的支持。 您将先创建一个基于 Northwind 数据库的对象模型,随后使用新的VB.NET 查询表达式查询 Northwind 数据库。

我们将使用Linq to Sql 设计器,从已有数据库中创建一个对象模型。而后,将着眼于映射表之间的实体关系,并且使用创建,更新与删除操作。紧接着,我们将探索如何使用事务,对象检索(retrieval)技术,存储过程集成与使用 Linq to Sql 标识对象 (identify)。

Linq to Sql 是一个语言无关的 Linq 项目组件。尽管展现在这篇文档中的示例仅仅与 Visual Basic 语言兼容, Linq to Sql 还是可以在支持 Linq 版本的C# 编译器中正常使用。

Linq 项目依赖许多内建于 VB.Net 中的新的关键字和语法,并且当前它们已被集成于Microsoft Visual Studio 2008 Beta 2之中。它将带给我们使用新IDE特性的机会,例如集成调试器,IntelliSense™(智能感知),以及编译时语法检查。


实验营目标
预估完成这次动手实验营的时间:60 分钟

这个实验营的目标是实践并学习有关Linq to SQL 与 VB.NET 程序集成的一些任务。我们将带您探索“CRUD ”操作——创建,接收,更新与删除,以及它们怎样在不使用外部方法的情况下完成 SQL查询或更新命令。您将获取程序中的实体如何映射至数据库表,以及怎样调节映射过程。

练习1 – 利用代码生成器建立对象模型
练习2 – 创建你的第一个 Linq to SQL 项目
练习3 – 创建一个对象模型
练习4 – 修改数据库中的数据
练习5 –运用更高级的特性



练习1 – 利用代码生成器建立对象模型
在这个练习中我们将看到如何透过可视化的 Linq 设计器简单地制作一个对象模型。下两个练习将深入研究在幕后究竟发生了什么:但是设计器已经为您完成了这一切!

步骤 1 – 创建一个 Linq 项目1.  单击 开始 | 程序 | Microsoft Visual Studio 2008 Beta 2 | Microsoft Visual Studio 2008 Beta 2 菜单命令。

2.  打开 Microsoft Visual Studio 后,单击 File | New | Project… 菜单命令

3.  在 New Project 对话框中的 Project types 中,单击Other Languages | Visual Basic

4.  在对话框右侧的 Templates 中,选择 Console Application

5.  在 Name 字段中填写 “Linq To Sql VB”为您的解决方案提供一个名字

6.  单击 OK



步骤 2 – 增加一个引用到System.Data.Linq程序集1.  在 Microsoft Visual Studio中,单击 Project | Add Reference… 菜单命令

2.  打开 Add Reference 对话框,确保 .NET 标签已被选择

3.  选取System.Data.Linq 程序集

4.  点击OK

在Module1.vb 中引入命名空间 System.Data.Linq ,切记放置于模块定义之前:

Imports System.Data.Linq


步骤 3 – 创建一个 Linq to Sql 文件1.  在 Microsoft Visual Studio中,单击 Project | Add New Item… 菜单命令

2.  点击右侧Templates 窗口中的Linq To Sql File

3.  为这个新项提供一个名字,在Name字段中输入“Northwind”

4.  点击OK


步骤 4 – 增加一个新的数据连接1.  在Microsoft Visual Studio中,点击 View | Server Explorer 菜单命令 (或者按下 Ctrl+W,L)

2.  在Server Explorer 窗口中点击 Connect to database 按钮

3.  弹出的 Add Connection 对话框中,在Server name 字段中输入“.\sqlexpress”,提供本地数据库服务器地址

4.  使用Select or enter a database name 组合框,更改数据库为 “Northwind”

5.  点击OK
#1  
发表新主题 回复该主题
本主题被查看1205次, 共1个帖子, 1页, 当前为第1页     选择页数: 1      跳转到第







现在的时间是 2008-07-24 13:37:03

版权所有 商都网教育宝典
         Powered by Discuz!NT 1.0.6666    Copyright © 2001-2008 Comsenz Inc.
Processed in 0.064 seconds