zoukankan      html  css  js  c++  java
  • Linq to sql(九):其它补充(二)

    已编译查询

           对于一些在项目中经常被用到的查询可以封装成已编译查询,这样就能提高执行效率:

    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);

    }

           调用查询方式如下:   

            GridView1.DataSource = Queries.CustomersByCity(ctx, "London");

            GridView1.DataBind();


    获取一些信息

            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/>");

      上面的代码执行结果如下:

    Provider类型:System.Data.Linq.SqlClient.SqlProvider
    数据库:Northwind
    表:dbo.Customers
    表达式:Table(Customer).Select(c => c)
    sql:SELECT [t0].[CustomerID], [t0].[CompanyName], [t0].[ContactName], [t0].[ContactTitle], [t0].[Address], [t0].[City], [t0].[Region], [t0].[PostalCode], [t0].[Country], [t0].[Phone], [t0].[Fax] FROM [dbo].[Customers] AS [t0]

  • 相关阅读:
    javascript的闭包的形成
    MongoDB 基础
    VirtualBox的四种网络连接方式
    jquery插件Asgrid开发小记
    jQuery插件开发指南[转]
    javascript对Dom操作中table添加行性能问题
    【对.NET系统架构改造的一点经验和教训】的技术要点的看法
    杭电1205
    杭电1248
    杭电2059
  • 原文地址:https://www.cnblogs.com/kevin2013/p/1749031.html
Copyright © 2011-2022 走看看