zoukankan      html  css  js  c++  java
  • Asp.NET笔记(三)--用linq实现三层架构的简单单表全查询

    用linq实现数据的简单全查询
    一、在Model层添加linq to Sql类
    二、在DAL层实现数据的全查询
    如:

       public class Comments_DAL
        {
            /// <summary>
            /// 查询所有留言信息
            /// </summary>
            /// <returns></returns>
            public List<Comments> SelectAll()
            {
                DataCommonDataContext db = new DataCommonDataContext();
    
               var result = from m in db.Comments  //这里需要引入程序集system.data.linq
                            select m;
                List<Comments> list = result.ToList();
                return list;
            }
      }

    三、在BLL层实现DAL层方法的调用
    如:

       public class Comments_BLL
        {
            //实例化DAL层的对应类
            Comments_DAL comments_DAL = new Comments_DAL();
            /// <summary>
            /// 查询所有留言信息
            /// </summary>
            /// <returns></returns>
            public List<Comments> SelectAll()
            {
                return comments_DAL.SelectAll();
            }
        }

    四、在UI层实现对BLL方法的调用和数据的展示
    如:

      在网页后台代码中

            //实例化BLL类对象
            Comments_BLL comments_BLL = new Comments_BLL();
            protected void Page_Load(object sender, EventArgs e)
            {
                //判断页面是非回发页面
                if (!Page.IsPostBack)
                {
                    List<Comments> lists = comments_BLL.SelectAll();
                    this.GridView1.DataSource = lists;
                    this.GridView1.DataBind();
                }
    
            }

     前台添加GridView1控件即可展示Comments表中的所有数据

  • 相关阅读:
    谈谈Nginx有哪些特点
    网站嵌入百度地图制作
    8张图理解Java
    linux问题-easy_install安装bpython时报错
    linux问题-Centos 安装Sublime text 3
    python例子-Nmap扫描IP并更新
    python例子-PyQuery抓取信息.
    python例子-MySQLdb和练习题
    python例子-线程和队列
    mysql问题-centos7中mysql远程连接问题
  • 原文地址:https://www.cnblogs.com/JuneDream/p/14147783.html
Copyright © 2011-2022 走看看