internal FunctionAttribute(FunctionType type, string name, string schema = null, string namespaceName = CodeFirstDatabaseSchema)
            : base(namespaceName, (name.Contains(".") ? name.Substring(name.IndexOf('.') + 1) : name))
        {
            ParameterTypeSemantics = ParameterTypeSemantics.AllowImplicitConversion;

            _Type = type;
            var i = name.LastIndexOf('.');

            if (i >= 0)
            {
                this.Schema = name.Remove(i);
            }
            if (schema != null)
            {
                this.Schema = schema;
            }

            switch (type)
            {
            case FunctionType.TableValuedFunction:
            case FunctionType.StoredProcedure:
                if (CodeFirstDatabaseSchema.Equals(namespaceName, StringComparison.Ordinal))
                {
                    throw new ArgumentException("The namespaceName parameter must be set for Table Valued Functions and Stored Procedures.");
                }
                break;
                //case FunctionType.ModelDefinedFunction:
                //	if (CodeFirstDatabaseSchema.EqualsOrdinal(namespaceName))
                //	{
                //		throw new ArgumentException("For Model Defined Functions the namespaceName parameter must be set to the namespace of the DbContext class.");
                //	}
                //	break;
                //default:
                //	if (!CodeFirstDatabaseSchema.Equals(namespaceName, StringComparison.Ordinal))
                //		throw new ArgumentException("The namespaceName parameter may only be set for Table Valued Functions.");
                //	break;
            }

            switch (type)
            {
            case FunctionType.StoredProcedure:
                //case FunctionType.NonComposableScalarValuedFunction:
                _IsComposable = false;
                _IsAggregate  = false;
                _IsBuiltIn    = false;
                _IsNiladic    = false;
                break;

            case FunctionType.TableValuedFunction:
            case FunctionType.ScalarValuedFunction:
                //case FunctionType.ModelDefinedFunction:
                _IsComposable = true;
                _IsAggregate  = false;
                _IsBuiltIn    = false;
                _IsNiladic    = false;
                break;

            //case FunctionType.AggregateFunction:
            //	this.IsComposable = true;
            //	this.IsAggregate = true;
            //	this.IsBuiltIn = false;
            //	this.IsNiladic = false;
            //	break;

            case FunctionType.BuiltInFunction:
                _IsComposable = true;
                _IsAggregate  = false;
                _IsBuiltIn    = true;
                _IsNiladic    = false;
                break;

            case FunctionType.NiladicFunction:
                _IsComposable = true;
                _IsAggregate  = false;
                _IsBuiltIn    = true;
                _IsNiladic    = true;
                break;
            }
        }
        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>());
            }
        }