NHibernate与存储过程相联,实际上也就是与sqlclient,oledb,等SqlCommand,sqldataadapter,等相联.其主要步骤如下:
public DataSet GetDs()
{
NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
ISessionFactoryImplementor factory = (ISessionFactoryImplementor)cfg.BuildSessionFactory();//这行重要
SqlCommand cmd = new SqlCommand();
cmd.CommandText ="Company_GetPagedBrandList";
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.Add("@startIndex", SqlDbType.Int);
cmd.Parameters["@startIndex"].Value = startIndex;
cmd.Parameters.Add("@endIndex", SqlDbType.Int);
cmd.Parameters["@endIndex"].Value = endIndex;
cmd.Parameters.Add("@brandId", SqlDbType.VarChar,10);
cmd.Parameters["@brandId"].Value = brandId;
SqlConnection conn = (SqlConnection)factory.OpenConnection();
cmd.Connection = conn;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}