lambda表达式3

强类型DataContext

NorthwindDataContext.cs
[code]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Linq;
using System.Data;

namespace DannyWeb
{
public class NorthwindDataContext : DataContext
{
public Table<Customer> Customers;
public NorthwindDataContext(IDbConnection connection) : base(connection) { }
public NorthwindDataContext(string connection) : base(connection) { }
}
}
[/code]

显示页
Default2.aspx
[code]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DannyWeb;

public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
NorthwindDataContext ctx = new NorthwindDataContext("server=.;database=Northwind;uid=sa;pwd=");
GridView1.DataSource = from c in ctx.Customers
where c.CustomerID.StartsWith("A")
select new { 顾?客¨ªID = c.CustomerID, 顾?客¨ª名? = c.Name, 城?市ºD = c.City };
GridView1.DataBind();
}
}
[/code]
显示结果:

2011-6-2 13:18 danny

显示日志:
Default2.aspx.cs
[code]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DannyWeb;
using System.IO;

public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
NorthwindDataContext ctx = new NorthwindDataContext("server=.;database=Northwind;uid=sa;pwd=");
StreamWriter sw = new StreamWriter(Server.MapPath("log.txt"), true);
ctx.Log = sw;
GridView1.DataSource = from c in ctx.Customers
where c.CustomerID.StartsWith("A")
select new { 顾?客¨ªID = c.CustomerID, 顾?客¨ª名? = c.Name, 城?市ºD = c.City };
GridView1.DataBind();
sw.Close();
}
}
[/code]
日志
log.txt
[code]
SELECT [t0].[CustomerID] AS [顾客ID], [t0].[ContactName] AS [顾客名], [t0].[City] AS [城市]
FROM [Customers] AS [t0]
WHERE [t0].[CustomerID] LIKE @p0
-- @p0: Input NVarChar (Size = 2; Prec = 0; Scale = 0) [A%]
-- Context: SqlProvider(Sql2000) Model: AttributedMetaModel Build: 4.0.30319.1
[/code]

2011-6-2 13:24 danny
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值