zoukankan      html  css  js  c++  java
  • NHibernate 做个小项目来试一下吧 四 (我们继续)

    昨天的问题,解决了,心情一直好到现在
    今天 完善了一下,我的EntityControl类,加上了返回 实体集合 和 返回单个实体的两个类
    当然了,这些代码我基本上采用了拿来主义 把飞鹰用 vb.net写的改成了C#
            public IList GetEntities(String query)
            
    {
                IList lst;
                ISession s
    =SessionFactory.OpenSession();
                ITransaction t
    =s.BeginTransaction();

                lst
    =s.Find(query);
                t.Commit();
                s.Close();
                
    return lst;
            }


            
    public Object GetEntity(Type theType,Object id)
            
    {
                Object obj;
                ISession s
    =SessionFactory.OpenSession();
                ITransaction t
    =s.BeginTransaction();
                obj
    =s.Load(theType,id);
                t.Commit();
                s.Close();
                
    return obj;
            }

    这样的话,我们就可以继续动作了,
    对于 usersdal这个类来说,还有一个重要的方法哪就是 处理用户的登录了,根据我现在所掌握的 NHibernate的知识 我只能写出这么一个方法,不知道是否还有更好的方法
            public users login(string user,string pwd)
            
    {
                users tmpuser;
                
    string hql="from guestbook.data.users as users where users.Name='"+user+"' and users.password='"+pwd+"'";
                IList lst
    =control.GetEntities(hql);

                
    if(lst.Count!=0)
                
    {
                    tmpuser
    =(users)lst[0];
                }

                
    else
                
    {
                    tmpuser
    =null;
                }

                
    return tmpuser;
                
            }
    利用 HQL 在中查询 如果有满足的用户 就返回一个 users类,没有就返回空
  • 相关阅读:
    CentOS 8.2上安装Cassandra Web部署
    CentOS 8.2上安装Apache Cassandra 3.11.9
    CentOS 8.2使用pgAdmin安装PostgreSQL 13.1
    windows 服务器报错处理,TLS升级为1.2
    网站跳转index.html
    安装fail2ban,防止ssh爆破及cc攻击
    服务器数据盘挂载
    2条命令在centos7.5中安装谷歌浏览器
    部署安装python3.7
    部署安装snort--入侵检测工具
  • 原文地址:https://www.cnblogs.com/9527/p/52558.html
Copyright © 2011-2022 走看看