internal static TChild BindChild <TChild>(TParent parent, Func <TChild, SafeLink <TParent> > getLink, TChild child) { SafeLink <TParent> link = getLink(child); Debug.Assert(link._value == null || link._value == parent, "don't try to hook up the same child to a different parent"); // this is the good stuff.. // only this method can actually make the link since _value is a private link._value = parent; return(child); }
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) { //---- 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>()); } }