Пример #1
0
        private async Task readFromDataReader(TNDMetaEntity metaEntity, List <TNDEntityItem> result, System.Data.SqlClient.SqlDataReader sqlDataReader)
        {
            // loop over NextResult
            bool next = true;

            while (next)
            {
                var                fieldCount        = sqlDataReader.FieldCount;
                string[]           names             = new string[fieldCount];
                Type[]             types             = new Type[fieldCount];
                TNDPropertyCache[] caches            = new TNDPropertyCache[fieldCount];
                object[]           values            = new object[fieldCount];
                int                idxMetaEntityName = -1;
                for (int idx = 0; idx < fieldCount; idx++)
                {
                    names[idx]  = sqlDataReader.GetName(idx);
                    types[idx]  = sqlDataReader.GetFieldType(idx);
                    caches[idx] = new TNDPropertyCache();
                    if (string.Equals(names[idx], "MetaEntityName", StringComparison.Ordinal))
                    {
                        idxMetaEntityName = idx;
                    }
                }
                // loop over Read
                bool read = true;
                while (read)
                {
                    var taskReadAsync = sqlDataReader.ReadAsync();
                    try {
                        read = await taskReadAsync;
                    } catch (Exception exception) {
                        throw;
                    }
                    if (read)
                    {
                        sqlDataReader.GetValues(values);
                        var item = new TNDEntityItem();
                        for (int idx = 0; idx < fieldCount; idx++)
                        {
                            if (idx == idxMetaEntityName)
                            {
                                item.MetaEntityName = values[idx] as string;
                            }
                            else
                            {
                                var property = new TNDProperty(names[idx], types[idx], values[idx]);
                                if (caches[idx] != null)
                                {
                                    property = caches[idx].GetOrCreate(property);
                                }
                                item.Property.Add(property);
                            }
                        }
                        if (item.MetaEntityName != null)
                        {
                            item.MetaEntity = this._ApplicationBuis.ApplicationModel.Configuration.FindMetaEntity(item.MetaEntityName);
                        }
                        if (item.MetaEntity == null)
                        {
                            item.MetaEntity     = metaEntity;
                            item.MetaEntityName = metaEntity.MetaEntityName;
                        }
                        result.Add(item);
                    }
                }
                var taskNextResult = sqlDataReader.NextResultAsync();
                try {
                    next = await taskNextResult;
                } catch (Exception exception) {
                    throw;
                }
            }
        }