Пример #1
0
 /// <summary>
 /// 是否存在记录
 /// </summary>
 /// <param name="sqlwhere">条件</param>
 /// <param name="files">查询字段</param>
 /// <param name="orderby">排序</param>
 /// <returns>bool</returns>
 public virtual T GetModel(string sqlwhere, string files, string orderby)
 {
     if (string.IsNullOrEmpty(sqlwhere))
     {
         sqlwhere = "1=1";
     }
     if (string.IsNullOrEmpty(files))
     {
         files = "*";
     }
     if (string.IsNullOrEmpty(orderby))
     {
         orderby = "id desc";
     }
     try
     {
         T t = WriteDataBase.SingleOrDefault <T>(Sql.Builder.Select(files).From(TableName).Where(sqlwhere).OrderBy(orderby));
         return(t);
     }
     catch (Exception ex)
     {
         LogHelper.Error(ex);
         WriteDataBase.CloseSharedConnection();
         return(null);
     }
     finally
     {
         WriteDataBase.CloseSharedConnection();
     }
 }
Пример #2
0
        /// <summary>
        /// 是否存在记录
        /// </summary>
        /// <param name="id">主键ID</param>
        /// <returns>bool</returns>
        public virtual T GetModel(int id)
        {
            string sqlwhere = string.Empty;

            if (id > 0)
            {
                sqlwhere = "id=" + id;
            }
            try
            {
                T t = WriteDataBase.SingleOrDefault <T>(Sql.Builder.From(TableName).Where(sqlwhere));
                return(t);
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                WriteDataBase.CloseSharedConnection();
                return(null);
            }
            finally
            {
                WriteDataBase.CloseSharedConnection();
            }
        }