易截截图软件、单文件、免安装、纯绿色、仅160KB

.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 Server 2005 中的同义词与复制

在2005中有同义词与复制的概念
同义词的主要作用是:
        一:宿短对象的名称,减少工作人员书写的时间,提高效率。我们知道访问数据库一个对象的通常最全的对象名称是:服务器名称。数据库名称。架构名称。对象名称
        二:同步数据。 ......

SQL触发器 实例教学


        ... 
      )
     用到的功能有: 
        1.如果我更改了学生的学号,我希望他的借书记录仍然与这个学生相关(也就是同时更改借书记录表的学号); 
        2.如果该学生已经 ......

ORACLE SQL语句优化


1) 选择最有效率的表名顺序(只在基于规则的优化器中有效):
ORACLE的解析器按照从右到左的顺序处理from子句中的表名,from子句中写在最后的表(基础表 driving table)将被最先处理,在from子句中包含多个表的情况下,你必须选择记录条数最少的表作为基础表。如果有3个以上的表连接查询, 那就需要选择交叉表(intersection ......

.NET学习手记之:linq to SQL(一)


一个简单的例子:
先建一个C#类:
引用System.Data.Linq.dll程序集,
using System.Data.Linq.Mapping和
using System.Data.Linq 两个空间。
[Table]
public class Inventory
{
   [Column]
   public string Make;
   [Column]
   public string Color;
 &nbs ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号