Beispiel #1
0
 /// <summary>
 /// 读取模型实例。
 /// </summary>
 /// <param name="sql">SQL脚本。</param>
 /// <returns>返回模型实例。</returns>
 protected TModel Get(SqlScript sql)
 {
     using (var reader = _db.ExecuteReader(sql.ToString()))
     {
         if (reader.Read())
         {
             return(Entity.Read <TModel>(reader));
         }
     }
     return(default(TModel));
 }
Beispiel #2
0
 /// <summary>
 /// 读取模型实例。
 /// </summary>
 /// <param name="sql">SQL脚本。</param>
 /// <param name="cancellationToken">取消标记。</param>
 /// <returns>返回模型实例。</returns>
 protected async Task <TModel> GetAsync(SqlScript sql, CancellationToken cancellationToken = new CancellationToken())
 {
     using (var reader = await _db.ExecuteReaderAsync(sql.ToString(), cancellationToken: cancellationToken))
     {
         if (await reader.ReadAsync(cancellationToken))
         {
             return(Entity.Read <TModel>(reader));
         }
     }
     return(default(TModel));
 }
Beispiel #3
0
        /// <summary>
        /// 读取模型实例列表。
        /// </summary>
        /// <param name="sql">SQL脚本。</param>
        /// <param name="cancellationToken">取消标记。</param>
        /// <returns>返回模型实例列表。</returns>
        protected async Task <IEnumerable <TModel> > LoadAsync(SqlScript sql, CancellationToken cancellationToken = new CancellationToken())
        {
            var models = new List <TModel>();

            using (var reader = await _db.ExecuteReaderAsync(sql.ToString(), cancellationToken: cancellationToken))
            {
                while (await reader.ReadAsync(cancellationToken))
                {
                    models.Add(Entity.Read <TModel>(reader));
                }
            }
            return(models);
        }
Beispiel #4
0
        /// <summary>
        /// 读取模型实例列表。
        /// </summary>
        /// <param name="sql">SQL脚本。</param>
        /// <returns>返回模型实例列表。</returns>
        protected IEnumerable <TModel> Load(SqlScript sql)
        {
            var models = new List <TModel>();

            using (var reader = _db.ExecuteReader(sql.ToString()))
            {
                while (reader.Read())
                {
                    models.Add(Entity.Read <TModel>(reader));
                }
            }
            return(models);
        }