zoukankan      html  css  js  c++  java
  • 05简单查询(单个数据库表表)

    在01的基础上继续。

    1 指定数据库的连接

    使用数据库文件

      Northwind db = new Northwind
                    (@"c:\data\northwnd.mdf");

    2 建立简单的查询

    2.1 获取Table

    取得table

     Table<Customer> Customers = null;
                // 方法1,使用GetTable
                //Customers = db.GetTable<Customer>();
                // 方法2,使用強類型
                Customers = db.Customers;

    2.3 使用Log功能

    输出自动产生的SQL,便于调试

     db.Log = Console.Out;

    2.4 查询代码

                // 查詢地址為London的客戶
                IQueryable<Customer> custQuery1 = null;
                // 方法1,查詢語法
                //custQuery1 =
                //    from cust in Customers
                //    where cust.City == "London"
                //    select cust;
                // 方法2,方法語法
                custQuery1 = Customers
                    .Where(n => n.City == "London");

    注意:推荐使用方法语法,查询语法最后还是使用方法语法。

    3 执行查询

    foreach (Customer cust in custQuery1)
    {
        Console.WriteLine("ID={0}, City={1}", cust.CustomerID,
            cust.City);
    }

    注意:执行时的延迟执行和立即执行。

  • 相关阅读:
    Java基本数据类型之间转换
    python 元组tuple
    python 列表List
    python 字符串
    python for循环
    python break/continue
    python while循环
    python条件判断if/else
    python运算符
    python变量
  • 原文地址:https://www.cnblogs.com/htht66/p/2306809.html
Copyright © 2011-2022 走看看