⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lazyload.aspx.cs

📁 数据库连接查询
💻 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.Collections.Generic;
using System.Linq.Expressions;

public partial class lazyload : System.Web.UI.Page
{
    NorthwindDataContext ctx = new NorthwindDataContext("server=srv-devdbhost;database=Northwind;uid=sa;pwd=Abcd1234");

 
    protected void Page_Load(object sender, EventArgs e)
    {
        StreamWriter sw = new StreamWriter(Server.MapPath("ll.txt"), false);
        ctx.Log = sw;


        //DataLoadOptions options = new DataLoadOptions();
        //options.LoadWith<Product>(p => p.Order_Details);
        //options.AssociateWith<Product>(p => p.Order_Details.Where(od => od.Quantity > 80));
        //ctx.LoadOptions = options;
        //var products = from p in ctx.Products select p;
        //foreach (var p in products)
        //{
        //    if (p.UnitPrice > 10)
        //        ShowDetail(p.Order_Details);

        //}

        //var products = from p in ctx.Products
        //               where p.UnitPrice > 50
        //               select p;
        //foreach (var p in products)
        //{
        //    Response.Write(p.Order_Details.Count() + "<br>");
        //    foreach (var o in p.Order_Details)
        //    {
        //        Response.Write(p.ProductID + ":" + o.OrderID + "<br>");
        //    }
        //}


       
//var products = from p in ctx.Products
//               where p.UnitPrice > 50
//               select p;
//foreach (var p in products)
//{
//    foreach (var o in p.Order_Details)
//    {
//        Response.Write(p.ProductID + ":" + o.OrderID);
//    }
//}

     
        //DataLoadOptions options = new DataLoadOptions();
        //options.LoadWith<Customer>(p => p.Orders);
        //ctx.LoadOptions = options;

        //List<Customer> data = ctx.Customers.ToList();
        //Customer c1 = ctx.Customers.Single(customer => customer.CustomerID == "ANATR");
        //c1.ContactName = "zhuye";
        //ctx.SubmitChanges();
        //Customer c2 = ctx.Customers.Single(customer => customer.CustomerID == "ANATR");
        //Response.Write(c2.ContactName);

        //ctx.DeferredLoadingEnabled = false;

        //DataLoadOptions options = new DataLoadOptions();
        //options.LoadWith<Customer>(p => p.Orders);
        //ctx.LoadOptions = options;

        //Customer c = new Customer { CustomerID = "ALFKI", ContactName = "zhuye", CompanyName = "1111" };

        //ctx.Customers.Attach(c, true);
        //ctx.SubmitChanges();



        //DataLoadOptions options = new DataLoadOptions();
        //options.LoadWith<Customer>(c => c.Orders);
        //options.LoadWith<Order>(o => o.Order_Details);
        //ctx.LoadOptions = options;
        //IEnumerable<Customer> customers = ctx.Customers.ToList<Customer>();

        //DataLoadOptions options = new DataLoadOptions();
        //options.LoadWith<Product>(c => c.Category);
        //options.LoadWith<Product>(c => c.Order_Details);
        //options.LoadWith<Order_Detail>(o => o.Order);
        //ctx.LoadOptions = options;
        //IEnumerable<Product> products = ctx.Products.ToList<Product>();


//   IQueryable q = from c in ctx.Customers select c;

//ParameterExpression p = Expression.Parameter(typeof(Customer), "c");

//LambdaExpression predicate = Expression.Lambda("c.City = 'London'", p);

//Expression where = Expression(q.Expression, predicate);

//q = q.CreateQuery(where);


        //var query = from c in ctx.Customers select c;
        //var newquery = (from c in query select c).OrderBy(c => c.CustomerID);

        //GridView1.DataSource = newquery;
        //GridView1.DataBind();

        ctx.Employees.Add(new Employee { EmployeeID=99, LastName="bbbbb", FirstName="aaaa"});
        ctx.SubmitChanges();
        sw.Close();
    }

    private void ShowDetail(EntitySet<Order_Detail> orderdetails)
    {
        foreach (var o in orderdetails)
       {
           Response.Write(o.Quantity + "<br>");
       }
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -