关闭

spring.net 获得session

641人阅读 评论(0) 收藏 举报
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Dynamic;
using Domain;
using Spring.Data.NHibernate.Generic.Support;
using Spring.Data.NHibernate.Generic;

using NHibernate.Criterion;
namespace Dao.Implement
{
    
  public  class cpysiteclassRepository : RepositoryBase<cpysiteclass>,IcpysiteclassRepository
    {

      public IList<cpysiteclass> xx(NHibernate.ISession session)
      {
          //Hql
          //写法1
          //return _session.CreateQuery("from Customer c where c.Firstname='" + firstname + "'")
          //    .List<Customer>();

          //写法2:位置型参数
          //return _session.CreateQuery("from Customer c where c.Firstname=?")
          //    .SetString(0, firstname)
          //    .List<Customer>();

          //写法3:命名型参数(推荐)
          //return session.CreateQuery("from cpysiteclass c where c.classname=:fn")
          //    .SetString("fn", "药易通2")
          //    .List<cpysiteclass>();

         // return session.CreateQuery("from cpysiteclass c where c.classname like '药%' order by c.classid asc")
              
          //    .List<cpysiteclass>();

          //hql
          return session.CreateCriteria<cpysiteclass>().List<cpysiteclass>();

          //条件查询
        //  return session.CreateCriteria(typeof(cpysiteclass))
        //.Add(Restrictions.Like("classname", "药%"))
        //.AddOrder(new NHibernate.Criterion.Order("classid", true))
       
        //.List<cpysiteclass>();
          //条件查询


          // sql
         // return session.CreateSQLQuery("select * from cpysiteclass where classname like '药%' order by classid asc ").AddEntity("ss", typeof(cpysiteclass)).List<cpysiteclass>();

          //sql


          //更新
         


      
      }
      public IQueryable<cpysiteclass> LoadAllByPage(out long total, int page, int rows, string order, string sort)
        {
            var list = this.LoadAll();

            total = list.LongCount();

            list = list.OrderBy(sort + " " + order);
            list = list.Skip((page - 1) * rows).Take(rows);

            return list;
        }

      public IQueryable<cpysiteclass> LoadAllEnable()
        {
            return from li in this.LoadAll()
                  
                  
                   select li;
        }

      public IList<cpysiteclass> Searchbyclassfid(int fid)
      {
          //string hql = " from cpysiteclass u1 where u1.classfid = ? ";
          string hql = " from cpysiteclass where  classfid = ? ";
          return HibernateTemplate.Find<cpysiteclass>(hql, new object[] { fid });
          //this.HibernateTemplate.SessionFactory.GetCurrentSession
       
          //this.Session
         // this.HibernateTemplate.SessionFactory.OpenSession

          //HibernateCallback

          //得到session
          // return this.HibernateTemplate.ExecuteFind<cpysiteclass>(new FindHibernateDelegate<cpysiteclass>(xx));


          //return this.HibernateTemplate.ExecuteFind<cpysiteclass>(new xxx<cpysiteclass>());
          
          


      }

    }

  public class xxx<T> : IFindHibernateCallback<T> where T : class
  {
   public   System.Collections.Generic.IList<T> DoInHibernate(NHibernate.ISession session)
      {

          return session.CreateCriteria<T>().List<T>();


          
      }
  
  
  }
}


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:845490次
    • 积分:8821
    • 等级:
    • 排名:第2144名
    • 原创:119篇
    • 转载:392篇
    • 译文:0篇
    • 评论:57条
    最新评论