예제 #1
0
        /// <summary>
        /// 获取异常日志
        /// </summary>
        /// <param name="id">标识Id</param>
        /// <returns>异常日志</returns>
        public ExceptionLog Single(Guid id)
        {
            string sql = "SELECT * FROM ExceptionLogs WHERE \"Id\" = @Id";

            using (IDataReader reader = _SqlHelper.ExecuteReader(sql, new NpgsqlParameter("@Id", id)))
            {
                if (reader.Read())
                {
                    return(this.GetEntity(reader));
                }

                throw new NullReferenceException($"Id为\"{id}\"的日志不存在!");
            }
        }
예제 #2
0
        //Internal

        #region # 获取唯一序列种子 —— SerialSeed SingleOrDefault(string seedName...
        /// <summary>
        /// 获取唯一序列种子,
        /// </summary>
        /// <param name="seedName">种子名称</param>
        /// <param name="prefix">前缀</param>
        /// <param name="timestamp">时间戳</param>
        /// <param name="serialLength">流水长度</param>
        /// <returns>序列种子</returns>
        /// <remarks>如没有,则返回null</remarks>
        public SerialSeed SingleOrDefault(string seedName, string prefix, string timestamp, int serialLength)
        {
            StringBuilder sqlBuilder = new StringBuilder();

            sqlBuilder.Append("SELECT * FROM SerialSeeds ");
            sqlBuilder.Append("WHERE \"Name\" = @Name ");
            sqlBuilder.Append("AND \"Prefix\" = @Prefix ");
            sqlBuilder.Append("AND \"Timestamp\" = @Timestamp ");
            sqlBuilder.Append("AND \"SerialLength\" = @SerialLength ");

            IDbDataParameter[] parameters =
            {
                new NpgsqlParameter("@Name",         seedName.ToDbValue()),
                new NpgsqlParameter("@Prefix",       prefix.ToDbValue()),
                new NpgsqlParameter("@Timestamp",    timestamp.ToDbValue()),
                new NpgsqlParameter("@SerialLength", serialLength.ToDbValue())
            };

            using (IDataReader reader = _SqlHelper.ExecuteReader(sqlBuilder.ToString(), parameters))
            {
                return(reader.Read() ? this.ToModel(reader) : null);
            }
        }