Linq 2 SQL - 经验之准备和工具 (一)

先准备一下数据库,以后所有的demo都建立在该数据库上
-- Run this script at any time, either to:
--   (a) Create the demo tables in a different database (see note in previous example)
--   (b) Restore the demo tables to their original state

if exists (select * from sysobjects where name = 'PurchaseItem') drop table PurchaseItem
if exists (select * from sysobjects where name = 'Purchase') drop table Purchase
if exists (select * from sysobjects where name = 'Customer') drop table Customer
if exists (select * from sysobjects where name = 'MedicalArticles') drop table MedicalArticles
if exists (select * from sysobjects where name = 'Product') drop table Product
go

create table Customer
(
	ID int not null primary key,
	Name nvarchar(30) not null,
	[Timestamp] timestamp
)

create table Purchase
(
	ID int not null primary key,
	CustomerID int null references Customer (ID),
	Date datetime not null,
	Description varchar(30) not null,
	Price decimal not null
)

create table PurchaseItem
(
	ID int not null primary key,
	PurchaseID int not null references Purchase (ID),
	Detail varchar(30) not null,
	Price decimal not null
)

create table MedicalArticles
(
	ID int not null primary key,
	Topic varchar (20),
	Abstract nvarchar (2000)	
)

create table Product
(
	ID int not null primary key,
	Description varchar(30) not null,
  	Discontinued bit not null,
  	LastSale datetime not null
)
go

insert Customer (ID, Name) values (1, 'Tom')
insert Customer (ID, Name) values (2, 'Dick')
insert Customer (ID, Name) values (3, 'Harry')
insert Customer (ID, Name) values (4, 'Mary')
insert Customer (ID, Name) values (5, 'Jay')

insert Purchase values (1, 1, '2006-1-1', 'Bike', 500)
insert Purchase values (2, 1, '2006-1-2', 'Holiday', 2000)
insert Purchase values (3, 2, '2007-1-3', 'Bike', 600)
insert Purchase values (4, 2, '2007-1-4', 'Phone', 300)
insert Purchase values (5, 3, '2007-1-5', 'Hat', 50)
insert Purchase values (6, 4, '2008-1-6', 'Car', 15000)
insert Purchase values (7, 4, '2008-1-7', 'Boat', 30000)
insert Purchase values (8, 4, '2008-1-8', 'Camera', 1200)
insert Purchase values (9, null, '2008-1-9', 'Jacket', 80)

insert PurchaseItem values (1, 2, 'Flight', 1500)
insert PurchaseItem values (2, 2, 'Accommodation', 500)
insert PurchaseItem values (3, 2, 'Camera', 400)

insert MedicalArticles values (1, 'Influenza', '<this is the abstract...>')
insert MedicalArticles values (2, 'Diabetes', '<this is the abstract...>')

insert Product values (1, 'Widget', 0, '2007-1-1')

print 'Done!'


再介绍一下一些适合LINQ 2 SQL开发的工具。

• LINQ to SQL Debug Visualizer, 这个工具可以继承到VS.NET中。下载地址搜索一下就有。下载文件包括一个可视化调试工具的.dll程序集(在bin\debug文件夹下),而且还包含了源代码!

安装步骤
1.关闭所有正在运行的Visual Studio 2008。
2.复制SqlServerQueryVisualizer.dll程序集到本地的\Program Files\Microsoft Visual Studio 9.0\Common7\Packages\Debugger\Visualizers目录下:

接下来调试的时候,就能用了。

• LINQPad, 刚才上面的数据库也是LINQPAD中的数据库案例。LinqPad官网

下篇我将介绍具体介绍在项目中使用LINQ2SQL的经验与心得


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值