Example #1
0
 /// <summary>
 /// 根据分组编码,获取分组名称
 /// </summary>
 /// <param name="Code">分组编码</param>
 /// <returns></returns>
 public static string GetGroupName(Guid?Code)
 {
     try
     {
         //获得当前运行的NHibernate实例
         using (ISession session = NHibernateHelper.GetCurrentSession())
         {
             //事务开始
             ITransaction transaction = session.BeginTransaction();
             ICriteria    criteria    = session.CreateCriteria <Group>();
             criteria.Add(Expression.Eq("Code", Code));
             IList <Group> list = criteria.List <Group>();
             //提交事务
             transaction.Commit();
             return(list[0].Name);
         }
     }
     catch (Exception ex)
     {
         NHibernateHelper.WriteErrorLog("分页获取功能分组信息", ex);
         throw;
     }
 }
Example #2
0
 /// <summary>
 /// 根据数据库编码,获取表
 /// </summary>
 /// <param name="databaseCode">数据库编码</param>
 /// <returns></returns>
 public static IList <Tables> GetTables(Guid databaseCode)
 {
     try
     {
         //获得当前运行的NHibernate实例
         using (ISession session = NHibernateHelper.GetCurrentSession())
         {
             //事务开始
             ITransaction transaction = session.BeginTransaction();
             ICriteria    criteria    = session.CreateCriteria <Tables>();
             criteria.Add(Expression.Eq("DatabaseCode", databaseCode));
             IList <Tables> list = criteria.AddOrder(Order.Asc("Id")).List <Tables>();
             //提交事务
             transaction.Commit();
             return(list);
         }
     }
     catch (Exception ex)
     {
         NHibernateHelper.WriteErrorLog("根据数据库编码,获取表", ex);
         throw;
     }
 }
Example #3
0
 /// <summary>
 /// 根据表编码,获取列字段
 /// </summary>
 /// <param name="tablesCode">表编码</param>
 /// <returns></returns>
 public static IList <Column> GetColumn(Guid tablesCode)
 {
     try
     {   //获得当前运行的NHibernate实例
         using (ISession session = NHibernateHelper.GetCurrentSession())
         {
             //事务开始
             ITransaction transaction = session.BeginTransaction();
             ICriteria    criteria    = session.CreateCriteria <Column>();
             criteria.Add(Expression.Eq("TablesCode", tablesCode));
             criteria.Add(Expression.Eq("FieldState", 1));//状态为启用
             IList <Column> list = criteria.SetCacheable(true).AddOrder(Order.Asc("Id")).List <Column>();
             //提交事务
             transaction.Commit();
             return(list);
         }
     }
     catch (Exception ex)
     {
         NHibernateHelper.WriteErrorLog("根据表编码,获取列字段", ex);
         throw;
     }
 }
Example #4
0
 /// <summary>
 /// 根据编码删除表并返回这个实体对象.
 /// </summary>
 /// <param name="code">编码</param>
 /// <returns>T</returns>
 public static T Delete(Guid code)
 {
     using (ISession session = NHibernateHelper.GetCurrentSession())
     {
         ITransaction transaction = session.BeginTransaction();
         try
         {
             T entity = GetProjectById(code);
             if (entity != null)
             {
                 session.Delete(entity);
             }
             session.Flush();
             transaction.Commit();
             return(entity);
         }
         catch (Exception ex)
         {
             NHibernateHelper.WriteErrorLog("NHibernate执行删除操作", ex);
             transaction.Rollback();
             return(default(T));
         }
     }
 }