public SafeLinkCollection(
     TParent parent,
     Func <TChild, SafeLink <TParent> > getLink,
     MetadataCollection <TChild> children)
     : base((MetadataCollection <TChild>)SafeLink <TParent> .BindChildren <TChild>(parent, getLink, (IEnumerable <TChild>)children))
 {
 }
 internal static IEnumerable <TChild> BindChildren <TChild>(
     TParent parent,
     Func <TChild, SafeLink <TParent> > getLink,
     IEnumerable <TChild> children)
 {
     foreach (TChild child in children)
     {
         SafeLink <TParent> .BindChild <TChild>(parent, getLink, child);
     }
     return(children);
 }
예제 #3
0
        internal EdmFunction(string name, string namespaceName, DataSpace dataSpace, EdmFunctionPayload payload)
            : base(name, namespaceName, dataSpace)
        {
            //---- name of the 'schema'
            //---- this is used by the SQL Gen utility and update pipeline to support generation of the correct function name in the store
            _schemaName = payload.Schema;
            _fullName   = NamespaceName + "." + Name;

            var returnParameters = payload.ReturnParameters;

            Debug.Assert(returnParameters.All((returnParameter) => returnParameter != null), "All return parameters must be non-null");
            Debug.Assert(
                returnParameters.All((returnParameter) => returnParameter.Mode == ParameterMode.ReturnValue),
                "Return parameter in a function must have the ParameterMode equal to ReturnValue.");

            _returnParameters = new ReadOnlyMetadataCollection <FunctionParameter>(
                returnParameters
                .Select(
                    (returnParameter) =>
                    SafeLink <EdmFunction> .BindChild(this, FunctionParameter.DeclaringFunctionLinker, returnParameter))
                .ToList());

            if (payload.IsAggregate.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.Aggregate, payload.IsAggregate.Value);
            }
            if (payload.IsBuiltIn.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.BuiltIn, payload.IsBuiltIn.Value);
            }
            if (payload.IsNiladic.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.NiladicFunction, payload.IsNiladic.Value);
            }
            if (payload.IsComposable.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.IsComposable, payload.IsComposable.Value);
            }
            if (payload.IsFromProviderManifest.HasValue)
            {
                SetFunctionAttribute(
                    ref _functionAttributes, FunctionAttributes.IsFromProviderManifest, payload.IsFromProviderManifest.Value);
            }
            if (payload.IsCachedStoreFunction.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.IsCachedStoreFunction, payload.IsCachedStoreFunction.Value);
            }
            if (payload.IsFunctionImport.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.IsFunctionImport, payload.IsFunctionImport.Value);
            }

            if (payload.ParameterTypeSemantics.HasValue)
            {
                _parameterTypeSemantics = payload.ParameterTypeSemantics.Value;
            }

            if (payload.StoreFunctionName != null)
            {
                _storeFunctionNameAttribute = payload.StoreFunctionName;
            }

            if (payload.EntitySets != null)
            {
                Debug.Assert(
                    _returnParameters.Count == payload.EntitySets.Length,
                    "The number of entity sets should match the number of return parameters");
                _entitySets = new ReadOnlyMetadataCollection <EntitySet>(payload.EntitySets);
            }
            else
            {
                var list = new List <EntitySet>();
                if (_returnParameters.Count != 0)
                {
                    Debug.Assert(
                        _returnParameters.Count == 1, "If there was more than one result set payload.EntitySets should not have been null");
                    list.Add(null);
                }
                _entitySets = new ReadOnlyMetadataCollection <EntitySet>(list);
            }

            if (payload.CommandText != null)
            {
                _commandTextAttribute = payload.CommandText;
            }

            if (payload.Parameters != null)
            {
                // validate the parameters
                foreach (var parameter in payload.Parameters)
                {
                    if (parameter == null)
                    {
                        throw new ArgumentException(Strings.ADP_CollectionParameterElementIsNull("parameters"));
                    }
                    Debug.Assert(
                        parameter.Mode != ParameterMode.ReturnValue, "No function parameter can have ParameterMode equal to ReturnValue.");
                }

                // Populate the parameters
                _parameters = new SafeLinkCollection <EdmFunction, FunctionParameter>(
                    this, FunctionParameter.DeclaringFunctionLinker, new MetadataCollection <FunctionParameter>(payload.Parameters));
            }
            else
            {
                _parameters = new ReadOnlyMetadataCollection <FunctionParameter>(new MetadataCollection <FunctionParameter>());
            }
        }
예제 #4
0
        internal EdmFunction(string name, string namespaceName, DataSpace dataSpace, EdmFunctionPayload payload)
            : base(name, namespaceName, dataSpace)
        {
            //---- name of the 'schema'
            //---- this is used by the SQL Gen utility and update pipeline to support generation of the correct function name in the store
            _schemaName = payload.Schema;

            var returnParameters = payload.ReturnParameters ?? new FunctionParameter[0];

            foreach (var returnParameter in returnParameters)
            {
                if (returnParameter == null)
                {
                    throw new ArgumentException(Strings.ADP_CollectionParameterElementIsNull("ReturnParameters"));
                }

                if (returnParameter.Mode != ParameterMode.ReturnValue)
                {
                    throw new ArgumentException(Strings.NonReturnParameterInReturnParameterCollection);
                }
            }

            _returnParameters = new ReadOnlyMetadataCollection <FunctionParameter>(
                returnParameters
                .Select(
                    returnParameter =>
                    SafeLink <EdmFunction> .BindChild(this, FunctionParameter.DeclaringFunctionLinker, returnParameter))
                .ToList());

            if (payload.IsAggregate.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.Aggregate, payload.IsAggregate.Value);
            }
            if (payload.IsBuiltIn.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.BuiltIn, payload.IsBuiltIn.Value);
            }
            if (payload.IsNiladic.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.NiladicFunction, payload.IsNiladic.Value);
            }
            if (payload.IsComposable.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.IsComposable, payload.IsComposable.Value);
            }
            if (payload.IsFromProviderManifest.HasValue)
            {
                SetFunctionAttribute(
                    ref _functionAttributes, FunctionAttributes.IsFromProviderManifest, payload.IsFromProviderManifest.Value);
            }
            if (payload.IsCachedStoreFunction.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.IsCachedStoreFunction, payload.IsCachedStoreFunction.Value);
            }
            if (payload.IsFunctionImport.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.IsFunctionImport, payload.IsFunctionImport.Value);
            }

            if (payload.ParameterTypeSemantics.HasValue)
            {
                _parameterTypeSemantics = payload.ParameterTypeSemantics.Value;
            }

            if (payload.StoreFunctionName != null)
            {
                _storeFunctionNameAttribute = payload.StoreFunctionName;
            }

            if (payload.EntitySets != null)
            {
                if (payload.EntitySets.Count != returnParameters.Count)
                {
                    throw new ArgumentException(Strings.NumberOfEntitySetsDoesNotMatchNumberOfReturnParameters);
                }

                _entitySets = new ReadOnlyCollection <EntitySet>(payload.EntitySets);
            }
            else
            {
                if (_returnParameters.Count > 1)
                {
                    throw new ArgumentException(Strings.NullEntitySetsForFunctionReturningMultipleResultSets);
                }

                _entitySets = new ReadOnlyCollection <EntitySet>(_returnParameters.Select(p => (EntitySet)null).ToList());
            }

            if (payload.CommandText != null)
            {
                _commandTextAttribute = payload.CommandText;
            }

            if (payload.Parameters != null)
            {
                // validate the parameters
                foreach (var parameter in payload.Parameters)
                {
                    if (parameter == null)
                    {
                        throw new ArgumentException(Strings.ADP_CollectionParameterElementIsNull("parameters"));
                    }

                    if (parameter.Mode == ParameterMode.ReturnValue)
                    {
                        throw new ArgumentException(Strings.ReturnParameterInInputParameterCollection);
                    }
                }

                // Populate the parameters
                _parameters = new SafeLinkCollection <EdmFunction, FunctionParameter>(
                    this, FunctionParameter.DeclaringFunctionLinker, new MetadataCollection <FunctionParameter>(payload.Parameters));
            }
            else
            {
                _parameters = new ReadOnlyMetadataCollection <FunctionParameter>(new MetadataCollection <FunctionParameter>());
            }
        }
 public SafeLinkCollection(TParent parent, Func <TChild, SafeLink <TParent> > getLink, MetadataCollection <TChild> children)
     : base((IList <TChild>)SafeLink <TParent> .BindChildren(parent, getLink, children))
 {
 }
        internal EdmFunction(
            string name,
            string namespaceName,
            DataSpace dataSpace,
            EdmFunctionPayload payload)
            : base(name, namespaceName, dataSpace)
        {
            this._schemaName = payload.Schema;
            IList <FunctionParameter> source = payload.ReturnParameters ?? (IList <FunctionParameter>) new FunctionParameter[0];

            foreach (FunctionParameter functionParameter in (IEnumerable <FunctionParameter>)source)
            {
                if (functionParameter == null)
                {
                    throw new ArgumentException(Strings.ADP_CollectionParameterElementIsNull((object)nameof(ReturnParameters)));
                }
                if (functionParameter.Mode != ParameterMode.ReturnValue)
                {
                    throw new ArgumentException(Strings.NonReturnParameterInReturnParameterCollection);
                }
            }
            this._returnParameters = new ReadOnlyMetadataCollection <FunctionParameter>(source.Select <FunctionParameter, FunctionParameter>((Func <FunctionParameter, FunctionParameter>)(returnParameter => SafeLink <EdmFunction> .BindChild <FunctionParameter>(this, FunctionParameter.DeclaringFunctionLinker, returnParameter))).ToList <FunctionParameter>());
            if (payload.IsAggregate.HasValue)
            {
                EdmFunction.SetFunctionAttribute(ref this._functionAttributes, EdmFunction.FunctionAttributes.Aggregate, payload.IsAggregate.Value);
            }
            if (payload.IsBuiltIn.HasValue)
            {
                EdmFunction.SetFunctionAttribute(ref this._functionAttributes, EdmFunction.FunctionAttributes.BuiltIn, payload.IsBuiltIn.Value);
            }
            if (payload.IsNiladic.HasValue)
            {
                EdmFunction.SetFunctionAttribute(ref this._functionAttributes, EdmFunction.FunctionAttributes.NiladicFunction, payload.IsNiladic.Value);
            }
            if (payload.IsComposable.HasValue)
            {
                EdmFunction.SetFunctionAttribute(ref this._functionAttributes, EdmFunction.FunctionAttributes.IsComposable, payload.IsComposable.Value);
            }
            if (payload.IsFromProviderManifest.HasValue)
            {
                EdmFunction.SetFunctionAttribute(ref this._functionAttributes, EdmFunction.FunctionAttributes.IsFromProviderManifest, payload.IsFromProviderManifest.Value);
            }
            if (payload.IsCachedStoreFunction.HasValue)
            {
                EdmFunction.SetFunctionAttribute(ref this._functionAttributes, EdmFunction.FunctionAttributes.IsCachedStoreFunction, payload.IsCachedStoreFunction.Value);
            }
            if (payload.IsFunctionImport.HasValue)
            {
                EdmFunction.SetFunctionAttribute(ref this._functionAttributes, EdmFunction.FunctionAttributes.IsFunctionImport, payload.IsFunctionImport.Value);
            }
            if (payload.ParameterTypeSemantics.HasValue)
            {
                this._parameterTypeSemantics = payload.ParameterTypeSemantics.Value;
            }
            if (payload.StoreFunctionName != null)
            {
                this._storeFunctionNameAttribute = payload.StoreFunctionName;
            }
            if (payload.EntitySets != null)
            {
                if (payload.EntitySets.Count != source.Count)
                {
                    throw new ArgumentException(Strings.NumberOfEntitySetsDoesNotMatchNumberOfReturnParameters);
                }
                this._entitySets = new ReadOnlyCollection <EntitySet>(payload.EntitySets);
            }
            else
            {
                if (this._returnParameters.Count > 1)
                {
                    throw new ArgumentException(Strings.NullEntitySetsForFunctionReturningMultipleResultSets);
                }
                this._entitySets = new ReadOnlyCollection <EntitySet>((IList <EntitySet>) this._returnParameters.Select <FunctionParameter, EntitySet>((Func <FunctionParameter, EntitySet>)(p => (EntitySet)null)).ToList <EntitySet>());
            }
            if (payload.CommandText != null)
            {
                this._commandTextAttribute = payload.CommandText;
            }
            if (payload.Parameters != null)
            {
                foreach (FunctionParameter parameter in (IEnumerable <FunctionParameter>)payload.Parameters)
                {
                    if (parameter == null)
                    {
                        throw new ArgumentException(Strings.ADP_CollectionParameterElementIsNull((object)"parameters"));
                    }
                    if (parameter.Mode == ParameterMode.ReturnValue)
                    {
                        throw new ArgumentException(Strings.ReturnParameterInInputParameterCollection);
                    }
                }
                this._parameters = (ReadOnlyMetadataCollection <FunctionParameter>) new SafeLinkCollection <EdmFunction, FunctionParameter>(this, FunctionParameter.DeclaringFunctionLinker, new MetadataCollection <FunctionParameter>((IEnumerable <FunctionParameter>)payload.Parameters));
            }
            else
            {
                this._parameters = new ReadOnlyMetadataCollection <FunctionParameter>(new MetadataCollection <FunctionParameter>());
            }
        }