Пример #1
0
        public T[] Complete <T>(LoadResult loadResult)
        {
            foreach (var include in SerializationHelper.RavenJObjectsToJsonDocuments(loadResult.Includes))
            {
                documentSession.TrackIncludedDocument(include);
            }

            if (typeof(T).IsArray)
            {
                var arrayOfArrays = loadResult.Results
                                    .Select(x =>
                {
                    if (x == null)
                    {
                        return(null);
                    }

                    var values = x.Value <RavenJArray>("$values").Cast <RavenJObject>();

                    var elementType = typeof(T).GetElementType();
                    var array       = values.Select(value =>
                    {
                        EnsureNotReadVetoed(value);
                        return(documentSession.ProjectionToInstance(value, elementType));
                    }).ToArray();
                    var newArray = Array.CreateInstance(elementType, array.Length);
                    Array.Copy(array, newArray, array.Length);
                    return(newArray);
                })
                                    .Cast <T>()
                                    .ToArray();

                return(arrayOfArrays);
            }

            var items = ParseResults <T>(loadResult.Results)
                        .ToArray();

            if (items.Length > ids.Length)
            {
                throw new InvalidOperationException(String.Format("A load was attempted with transformer {0}, and more than one item was returned per entity - please use {1}[] as the projection type instead of {1}",
                                                                  transformer,
                                                                  typeof(T).Name));
            }

            return(items);
        }