📄 other.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.IO;
using System.Data.Linq;
using System.Data.Linq.Mapping;
public partial class other : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//String path = @"C:\Northwind.map";
//XmlMappingSource xms = XmlMappingSource.FromXml(File.ReadAllText(path));
//Northwind ctx = new Northwind("server=srv-devdbhost;database=Northwind;uid=sa;pwd=Abcd1234", xms);
NorthwindDataContext ctx = new NorthwindDataContext("server=srv-devdbhost;database=Northwind;uid=sa;pwd=Abcd1234");
StreamWriter sw = new StreamWriter(Server.MapPath("other.txt"), false);
ctx.Log = sw;
//var count = (from c in ctx.Customers where c.Region == null select c).Count();
//Response.Write(count + "<br/>");
//var query = from emp in ctx.Employees select emp.ReportsTo;
//foreach (Nullable<int> r in query)
//{
// Response.Write(r.HasValue ? r.Value.ToString() + "<br/>" : "没有<br/>");
//}
//GridView1.DataSource = Queries.CustomersByCity(ctx, "London");
//GridView1.DataBind();
//var customer = ctx.Customers.Single(c => c.CustomerID == "AROUT");
//customer.ContactName = "zhuye";
//customer.Country = "Shanghai";
//Response.Write(string.Format("Name:{0},Country:{1}<br/>", customer.ContactName, customer.Country));
//customer = ctx.Customers.GetOriginalEntityState(customer);
//Response.Write(string.Format("Name:{0},Country:{1}<br/>", customer.ContactName, customer.Country));
var query = from c in ctx.Customers select c;
Response.Write("Provider类型:" + ctx.Mapping.ProviderType + "<br/>");
Response.Write("数据库:" + ctx.Mapping.DatabaseName + "<br/>");
Response.Write("表:" + ctx.Mapping.GetTable(typeof(Customer)).TableName + "<br/>");
Response.Write("表达式:" + query.Expression.ToString() + "<br/>");
Response.Write("sql:" + query.Provider.ToString() + "<br/>");
//var query = from c in ctx.Customers select c;
//ctx.Customers.RemoveAll(query);
//ctx.SubmitChanges();
//string sql = String.Format("delete from {0}", ctx.Mapping.GetTable(typeof(Customer)).TableName);
//ctx.ExecuteCommand(sql);
sw.Close();
}
}
static class Queries
{
public static Func<NorthwindDataContext, string, IQueryable<Customer>>
CustomersByCity = CompiledQuery.Compile((NorthwindDataContext ctx, string city) =>
from c in ctx.Customers where c.City == city select c);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -