1. 返回所有的会员:
     string query = "from Member";
     IList member = session.CreateQuery(query).List();

2. 返回以b开头的会员:
     string query = "from Member m where m.name like b%";
     IList members= session.CreateQuery(query).List();

3. 返回所有的会员ID和名称:
     string query = "select m.MemberId, m.Name from Member m";
     IList members = session.CreateQuery(query).List();
     注意:此处的MemberId, Name均为Member对象的属性.
     返回的并不是members对象的集合,而是一个一维数组的集合,
     其中array[0]为MemberId, array[1]为Name

4. 返回会员的总数:(用此方法时,session 和transcation都不能关闭和提交,否则IEnumerrator将取不到数据)
     string query = "select count(*) from Member";
     IEnumerator e = Session.CreateQuery(query).Enumerable().GetEnumerator();
     e.MoveNext;
     int rowCount = (int)(e.Current);

5. 返回指定(从20-40)的会员
     string query = "from Member";
     IList Members = session.CreateQuery(query)
                                 .SetFirstResult(20).SetMaxResults(20).List()

 

 

Nhiberante执行sql语句

Using Nhibernate.Engine;

 

string sql = "update s_companyconfig set isvalid={0} where numconpanyid={1} and numModelId={2}";

        sql = string.Format(sql, numVlaid, numcompanyid, numModel);

        NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();

        ISessionFactoryImplementor factory = (ISessionFactoryImplementor)cfg.BuildSessionFactory();

        System.Data.IDbCommand cmd = new System.Data.SqlClient.SqlCommand();

        cmd.CommandText = sql;

        System.Data.IDbConnection conn = factory.OpenConnection();

        cmd.Connection = conn;

        conn.Open();

        cmd.ExecuteNonQuery();

        conn.Close();

 posted on 2008-10-08 15:29  隔山打牛  阅读(598)  评论(0编辑  收藏  举报