LINQ to sql详细教程
运行程序后在网站所在目录生成了log.txt,每次查询都会把诸如下面的日志追加到文本文件中:
SELECT [t0].[CustomerID], [t0].[ContactName], [t0].[City] FROM [Customers] AS [t0]
WHERE [t0].[CustomerID] LIKE @p0
-- @p0: Input String (Size = 2; Prec = 0; Scale = 0) [A%]
-- Context: SqlProvider(Sql2005) Model: AttributedMetaModel Build: 3.5.20706.1 应该说这样的日志对于调试程序是非常有帮助的。
探究查询
using System.Data.Common;
using System.Collections.Generic;
NorthwindDataContext ctx = new NorthwindDataContext("server=xxx;database=Northwind;uid=xxx;pwd=xxx"); var select = from c in ctx.Customers where c.CustomerID.StartsWith("A") select new { 顾客ID = c.CustomerID, 顾客名 = c.Name, 城市 = c.City }; DbCommand cmd = ctx.GetCommand(select); Response.Write(cmd.CommandText + "<br/>"); foreach (DbParameter parm in cmd.Parameters)
Response.Write(string.Format("参数名:{0},参数值:{1}<br/>", parm.ParameterName, parm.Value)); Customer customer = ctx.Customers.First(); customer.Name = "zhuye";
IList<object> queryText = ctx.GetChangeSet().ModifiedEntities; Response.Write(((Customer)queryText[0]).Name);
在这里,我们通过DataContext的GetCommand方法获取了查询对应的DbCommand,并且输出了CommandText和所有的DbParameter。之后,我们又通过GetChangeSet方法获取了修改后的实体,并输出了修改内容。
执行查询
orthwindDataContext ctx = new NorthwindDataContext("server=xxx;database=Northwind;uid=xxx;pwd=xxx"); ring newcity = "Shanghai";
x.ExecuteCommand("update Customers set City={0} where CustomerID like 'A%'", newcity);
Enumerable<Customer> customers = ctx.ExecuteQuery<Customer>("select * from Customers where CustomerID like 'A%'"ridView1.DataSource = customers;
专题三 LINQ to SQL Hands-On实训教程系列 教学目标掌握使用设计器访问SQL ...在“一”的一方CustomOrder类中加入用于 保存订单详细集合的私有变量的声明 ...
Linq to sql 中文教程_理学_高等教育_教育专区。学习 linq to sql的不错资料哦近日,利用半天的空闲时间学习了 LINQ to SQL。 Linq to sql(或者叫 DLINQ)是...
LINQ to SQL语法及实例大... 106页 2下载券 LINQ中文教程 95页 免费 101...该属性具体映射 到数据库中的表或者表的某一列的方法,下面通 过一个具体的...
使用LINQ to SQL 创建模型类_信息与通信_工程科技_专业资料。在本教程中,...在控制器中,我们针对接口 而不是具体的类编写所有代码。Repository 模式的优势...
LINQ to SQL语法及实例大... 106页 2下载券 LINQ中文教程 95页 免费 101...LINQ to SQL快速上手 step by step 宋海军 Step1:建立数据库 ? 在使用Linq ...
LINQ to SQL语法及实例大... 106页 免费 LINQ中文教程 95页 免费 Entity_...下一节将详细介绍 DataContext 实例和 LINQ 中的表对象。 在处理 LINQ to SQL...
叧是具体的实现略 有一些丌同。今天向大家简单的介绍一下,如何使用 linq to ... 使用LINQ to SQL采用Rep... 7页 1下载券 LINQ中文教程 95页 免费 LINQ ...
LINQ TO SQL技术小结_计算机软件及应用_IT/计算机_专业资料。VS2010 创建 ...是在学习过程中进行的简单 实验,所以没进行一些详细特殊情况的处理,如操作失败等...
本篇详细说明一下 Select 和 Count/Sum/Min/Max/Avg。 Select/Distinct 操作... LINQ中文教程 95页 免费 101个LINQ 例子 64页 免费 LINQ to SQL 13页 ...
具体步骤(强类型) 1. 为项目添加“LINQ to SQL类”; 2. 将“服务器资源... LINQ中文教程 95页 免费 LINQ to SQL语法及实例大... 106页 2下载券 101...
热门文档