/// <summary>
 /// 执行结果。
 /// </summary>
 /// <param name="reader">数据读取器。</param>
 /// <returns>执行结果。</returns>
 public IEnumerable <object> GetResult(DbDataReader reader)
 {
     if (Initialize())
     {
         var type  = typeof(HashSet <>).MakeGenericType(Metadata.ClrType);
         var items = new OutputContentCollection(this, Activator.CreateInstance(type));
         while (reader.Read())
         {
             RegisterItem(reader, items);
         }
         return(items);
     }
     return(GetResultObjectItem(reader));
 }
Exemple #2
0
 /// <summary>
 /// 执行结果。
 /// </summary>
 /// <param name="reader">数据读取器。</param>
 /// <returns>执行结果。</returns>
 public IEnumerable <object> GetResult(DbDataReader reader)
 {
     Initialize();
     if (!HasCollectionProperty)
     {
         return(CreateSimpleCollection(reader));
     }
     else
     {
         var type  = typeof(HashSet <>).MakeGenericType(Metadata.ClrType);
         var items = new OutputContentCollection((CollectionOutputInfo)this, Activator.CreateInstance(type));
         while (reader.Read())
         {
             LoadDataToContent(reader, items);
         }
         return(items.Content as IEnumerable <object>);
     }
 }
        //注册使用内容项,用于生成集合属性用。
        private void RegisterItem(DbDataReader reader, OutputContentCollection collection)
        {
            string key = string.Join("_", ItemKeyFields.Select(a => reader.GetValue(a).ToString()).ToArray());

            if (!collection.TryGetValue(key, out OutputContentItem item))
            {
                item = new OutputContentItem();
                var content = CreateItem(reader, item);
                if (content != null)
                {
                    item.Content = content;
                    collection.Add(key, item);
                }
            }
            foreach (var kv in item.Collections)
            {
                kv.Key.RegisterItem(reader, kv.Value);
            }
        }