/// <summary>
 /// Initializes a new instance of Entity Type
 /// </summary>
 /// <param name="name">name of the entity type</param>
 /// <param name="namespaceName">namespace of the entity type</param>
 /// <param name="version">version of the entity type</param>
 /// <param name="dataSpace">dataSpace in which this edmtype belongs to</param>
 /// <exception cref="System.ArgumentNullException">Thrown if either name, namespace or version arguments are null</exception>
 internal EntityTypeBase(string name, string namespaceName, DataSpace dataSpace)
     : base(name, namespaceName, dataSpace)
 {
     _keyMembers = new ReadOnlyMetadataCollection <EdmMember>(new MetadataCollection <EdmMember>());
 }
예제 #2
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   = this.NamespaceName + "." + this.Name;

            FunctionParameter[] 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 <FunctionParameter>(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 (FunctionParameter parameter in payload.Parameters)
                {
                    if (parameter == null)
                    {
                        throw EntityUtil.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>());
            }
        }