private static ComplexInstanceCollection GetComplexInstanceCollection(IRandomNumberGenerator random, EdmModel model = null, ODataVersion version = ODataVersion.V4)
        {
            var complex = GetComplexInstance(random, model, version);
            int numinstances = random.ChooseFrom(new[] { 0, 1, 3 });
            var payload = new ComplexInstanceCollection(GenerateSimilarComplexInstances(random, complex, numinstances).ToArray());
            if (model != null)
            {
                var container = model.EntityContainersAcrossModels().Single() as EdmEntityContainer;
                var collectionType = new EdmCollectionType((model.FindDeclaredType(complex.FullTypeName) as EdmComplexType).ToTypeReference());

                var function = new EdmFunction(container.Namespace, "GetComplexInstances", collectionType.ToTypeReference());
                var functionImport = container.AddFunctionImport("GetComplexInstances", function);

                payload.AddAnnotation(new FunctionAnnotation() { FunctionImport = functionImport });
                payload.AddAnnotation(new DataTypeAnnotation() { EdmDataType = collectionType });
            }

            return payload;
        }