.NET学习手记之:linq to SQL(二)
在Visual Studio 2008 中使用O/R设计器:
点添加项目,选择创建Linq to SQL项目,使用服务器资源管理器连接Northwind数据库,将Customers和Orders两个表拖到设计界面上,系统会自动创建app.config和Northwid.designer.cs,前者是配置连接数据库的连接字串;后者会生成一个继承自DataContext的类:NorthwindDataContext。
使用linq调出数据:
static void Main(string[] args)
{
NorthwindDataContext dc= new NorthwindDataContext();
dc.Log=Console.Out;
var query=from c in dc.Customers
join o in dc.Orders on c.CustomerID equals o.CustomerID
orderby c.CustomerID
select new {
c.CustomeriD,c.CompanyName,c.Country,o.OrderID,o.OrderDate};
foreach(var item in query)
{
Console.WriteLine(item.CustomerID+"|"+item.CompanyName
+"|"+item.Country+"|"+item.OrderID
+"|"+item.OrderDate);
}
}
使用存储过程:
将存储过程拖到O/R设计器的右侧区域。
static void Main(string[] args)
{
NorthwindDataContext dc= new NorthwindDataContext();
ISingleResult<Ten_Most_Expensive_ProductsResult> result=
dc.Ten_Most_Expensive_Products();
foreach(Ten_Most_Expensive_ProductsResult item in result)
{
Console.WriteLine(item.TenMostExpensiveProducts+"|"+
item.UnitPrice);
}
}
相关文档:
请教大家一个有关SQL交驻报表查询问题,欢迎各位指教!
我想把图1的使用信息,使用SQL语句,实现如图2的结果。
表名
序号
字段名
a
1
c
a
2
d
a
3
e
a
4
f
a
5
g
b
1
h
b
2
i
b
3
j
b
4
k
b
5
l
c
1
m
c
2
n
c
3
o
c
4
p
c
5
q
图1
表名
序号
1
2
3
4
5
......
在2005中有同义词与复制的概念
同义词的主要作用是:
一:宿短对象的名称,减少工作人员书写的时间,提高效率。我们知道访问数据库一个对象的通常最全的对象名称是:服务器名称。数据库名称。架构名称。对象名称
二:同步数据。 ......
...
)
用到的功能有:
1.如果我更改了学生的学号,我希望他的借书记录仍然与这个学生相关(也就是同时更改借书记录表的学号);
2.如果该学生已经 ......
1) 选择最有效率的表名顺序(只在基于规则的优化器中有效):
ORACLE的解析器按照从右到左的顺序处理from子句中的表名,from子句中写在最后的表(基础表 driving table)将被最先处理,在from子句中包含多个表的情况下,你必须选择记录条数最少的表作为基础表。如果有3个以上的表连接查询, 那就需要选择交叉表(intersection ......
/*----------------------------------------------------------------
-- Author :feixianxxx(poofly)
-- Date :2010-04-20 20:10:41
-- Version:
-- Microsoft SQL Server 2008 (SP1) - ......