public void WriteFunctionImportHeader_writes_element_and_attributes() { var fixture = new Fixture(); var complexType = new ComplexType("CT", "N", DataSpace.CSpace); var returnParameter = new FunctionParameter( "ReturnValue", TypeUsage.CreateDefaultTypeUsage(complexType.GetCollectionType()), ParameterMode.ReturnValue); var functionPayload = new EdmFunctionPayload { IsComposable = true, ReturnParameters = new[] { returnParameter }, }; var functionImport = new EdmFunction("foo", "nction", DataSpace.CSpace, functionPayload); fixture.Writer.WriteFunctionImportElementHeader(functionImport); Assert.Equal( "<FunctionImport Name=\"foo\" IsComposable=\"true\"", fixture.ToString()); }
public void VisitEdmEntityContainer_visits_function_imports() { var functionPayload = new EdmFunctionPayload { IsFunctionImport = true }; var functionImport = new EdmFunction("f", "N", DataSpace.CSpace, functionPayload); var model = new EdmModel(DataSpace.CSpace); model.Container.AddFunctionImport(functionImport); var visitorMock = new Mock<EdmModelVisitor> { CallBase = true }; visitorMock.Object.VisitEdmModel(model); visitorMock.Verify(v => v.VisitFunctionImports(model.Container, It.IsAny<IEnumerable<EdmFunction>>()), Times.Once()); visitorMock.Verify(v => v.VisitFunctionImport(functionImport), Times.Once()); }
public void WriteFunctionImportHeader_writes_IsComposable_attribute_if_it_is_false() { var fixture = new Fixture(); var returnParameter = new FunctionParameter( "ReturnValue", TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32)), ParameterMode.ReturnValue); var functionPayload = new EdmFunctionPayload { IsComposable = false, ReturnParameters = new[] { returnParameter }, }; var functionImport = new EdmFunction("foo", "nction", DataSpace.CSpace, functionPayload); fixture.Writer.WriteFunctionImportElementHeader(functionImport); Assert.Equal( "<FunctionImport Name=\"foo\"", fixture.ToString()); }
public void VisitEdmFunction_should_visit_edm_function_parameters() { var visitorMock = new Mock<EdmModelVisitor> { CallBase = true }; var functionParameter = new FunctionParameter( "P", TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)), ParameterMode.In); var functionPayload = new EdmFunctionPayload { Parameters = new[] { functionParameter } }; var function = new EdmFunction("F", "N", DataSpace.SSpace, functionPayload); visitorMock.Object.VisitEdmFunction(function); visitorMock.Verify(v => v.VisitMetadataItem(functionParameter), Times.Once()); visitorMock.Verify(v => v.VisitFunctionParameter(functionParameter), Times.Once()); }
/// <summary> /// Creates the and add function. /// </summary> /// <param name="item">The item.</param> /// <param name="name">The name.</param> /// <param name="parameters">The parameters.</param> /// <param name="returnValues">The return values.</param> /// <param name="body">The body.</param> /// <returns></returns> public static EdmFunction CreateAndAddFunction( this EdmModel item, string name, IList<FunctionParameter> parameters, IList<FunctionParameter> returnValues, string body = null ) { var payload = new EdmFunctionPayload { StoreFunctionName = name, Parameters = parameters, ReturnParameters = returnValues, Schema = item.GetDefaultSchema() }; EdmFunction function = EdmFunction.Create( name, item.GetDefaultNamespace(), item.DataSpace, payload, null ); item.AddItem( function ); return function; }
public static EdmFunction AddFunction(this EdmModel database, string name, EdmFunctionPayload functionPayload) { DebugCheck.NotNull(database); DebugCheck.NotEmpty(name); var uniqueIdentifier = database.Functions.UniquifyName(name); var function = new EdmFunction( uniqueIdentifier, DefaultStoreNamespace, DataSpace.SSpace, functionPayload); database.AddItem(function); return function; }
/// <summary> /// The factory method for constructing the <see cref="T:System.Data.Entity.Core.Metadata.Edm.EdmFunction" /> object. /// </summary> /// <param name="name">The name of the function.</param> /// <param name="namespaceName">The namespace of the function.</param> /// <param name="dataSpace">The namespace the function belongs to.</param> /// <param name="payload">Additional function attributes and properties.</param> /// <param name="metadataProperties">Metadata properties that will be added to the function. Can be null.</param> /// <returns> /// A new, read-only instance of the <see cref="T:System.Data.Entity.Core.Metadata.Edm.EdmFunction" /> type. /// </returns> public static EdmFunction Create( string name, string namespaceName, DataSpace dataSpace, EdmFunctionPayload payload, IEnumerable <MetadataProperty> metadataProperties) { Check.NotEmpty(name, nameof(name)); Check.NotEmpty(namespaceName, nameof(namespaceName)); EdmFunction edmFunction = new EdmFunction(name, namespaceName, dataSpace, payload); if (metadataProperties != null) { edmFunction.AddMetadataProperties(metadataProperties.ToList <MetadataProperty>()); } edmFunction.SetReadOnly(); return(edmFunction); }
/// <summary> /// The factory method for constructing the <see cref="EdmFunction" /> object. /// </summary> /// <param name="name">The name of the function.</param> /// <param name="namespaceName">The namespace of the function.</param> /// <param name="dataSpace">The namespace the function belongs to.</param> /// <param name="payload">Additional function attributes and properties.</param> /// <param name="metadataProperties">Metadata properties that will be added to the function. Can be null.</param> /// <returns> /// A new, read-only instance of the <see cref="EdmFunction" /> type. /// </returns> public static EdmFunction Create( string name, string namespaceName, DataSpace dataSpace, EdmFunctionPayload payload, IEnumerable <MetadataProperty> metadataProperties) { Check.NotNull(name, "name"); Check.NotNull(namespaceName, "namespaceName"); var function = new EdmFunction(name, namespaceName, dataSpace, payload); if (metadataProperties != null) { function.AddMetadataProperties(metadataProperties.ToList()); } function.SetReadOnly(); return(function); }
public EdmFunction Create(FunctionDescriptor functionDescriptor) { Debug.Assert(functionDescriptor != null, "functionDescriptor is null"); if (_schema == null && functionDescriptor.DatabaseSchema == null) { throw new InvalidOperationException( string.Format( "Database schema is not defined for function '{0}'. Either set a default database schema or use the DbFunctionEx attribute with non-null DatabaseSchema value.", functionDescriptor.Name)); } var functionPayload = new EdmFunctionPayload { Parameters = functionDescriptor .Parameters .Select( p => FunctionParameter.Create( p.Name, GetStorePrimitiveType( p.EdmType.BuiltInTypeKind == BuiltInTypeKind.EnumType ? ((EnumType)p.EdmType).UnderlyingType : p.EdmType), p.IsOutParam ? ParameterMode.InOut : ParameterMode.In)).ToArray(), ReturnParameters = CreateFunctionReturnParameters(functionDescriptor), IsComposable = functionDescriptor.StoreFunctionKind != StoreFunctionKind.StoredProcedure, Schema = functionDescriptor.DatabaseSchema ?? _schema, }; return EdmFunction.Create( functionDescriptor.Name, _namespace, DataSpace.SSpace, functionPayload, null); }
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>()); } }
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 void VisitFunctionImport_visits_function_import_input_and_returnparameters() { var typeUsage = TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32)); var inputParam = new FunctionParameter("p1", typeUsage, ParameterMode.In); var returnParam = new FunctionParameter("r", typeUsage, ParameterMode.ReturnValue); var functionPayload = new EdmFunctionPayload { IsFunctionImport = true, Parameters = new [] { inputParam }, ReturnParameters = new[] {returnParam} }; var functionImport = new EdmFunction("f", "N", DataSpace.CSpace, functionPayload); var visitorMock = new Mock<EdmModelVisitor> { CallBase = true }; visitorMock.Object.VisitFunctionImport(functionImport); visitorMock.Verify(v => v.VisitFunctionImportParameter(inputParam), Times.Once()); visitorMock.Verify(v => v.VisitFunctionImportReturnParameter(returnParam), Times.Once()); }
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>()); } }
private static DbCompiledModel CreateModel(NpgsqlConnection connection) { var dbModelBuilder = new DbModelBuilder(DbModelBuilderVersion.Latest); // Import Sets dbModelBuilder.Entity<Blog>(); dbModelBuilder.Entity<Post>(); dbModelBuilder.Entity<NoColumnsEntity>(); // Import function var dbModel = dbModelBuilder.Build(connection); var edmType = PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32); var payload = new EdmFunctionPayload { ParameterTypeSemantics = ParameterTypeSemantics.AllowImplicitConversion, Schema = "dbo", IsComposable = true, IsNiladic = false, IsBuiltIn = false, IsAggregate = false, IsFromProviderManifest = true, StoreFunctionName = "StoredAddFunction", ReturnParameters = new[] { FunctionParameter.Create("ReturnType", edmType, ParameterMode.ReturnValue) }, Parameters = new[] { FunctionParameter.Create("Value1", edmType, ParameterMode.In), FunctionParameter.Create("Value2", edmType, ParameterMode.In) } }; var myFunc = EdmFunction.Create("ClrStoredAddFunction", "BloggingContext", DataSpace.SSpace, payload, null); dbModel.StoreModel.AddItem(myFunc); var compiledModel = dbModel.Compile(); return compiledModel; }
private ModificationFunctionMapping GenerateFunctionMapping( ModificationOperator modificationOperator, EntitySetBase entitySetBase, EntityTypeBase entityTypeBase, DbDatabaseMapping databaseMapping, IEnumerable<EdmProperty> parameterProperties, IEnumerable<Tuple<ModificationFunctionMemberPath, EdmProperty>> iaFkProperties, IList<ColumnMappingBuilder> columnMappings, IEnumerable<EdmProperty> resultProperties = null, string functionNamePrefix = null) { DebugCheck.NotNull(entitySetBase); DebugCheck.NotNull(entityTypeBase); DebugCheck.NotNull(databaseMapping); DebugCheck.NotNull(parameterProperties); DebugCheck.NotNull(iaFkProperties); DebugCheck.NotNull(columnMappings); var useOriginalValues = modificationOperator == ModificationOperator.Delete; var parameterMappingGenerator = new FunctionParameterMappingGenerator(_providerManifest); var parameterBindings = parameterMappingGenerator .Generate( modificationOperator == ModificationOperator.Insert && IsTableSplitDependent(entityTypeBase, databaseMapping) ? ModificationOperator.Update : modificationOperator, parameterProperties, columnMappings, new List<EdmProperty>(), useOriginalValues) .Concat( parameterMappingGenerator .Generate(iaFkProperties, useOriginalValues)) .ToList(); var parameters = parameterBindings.Select(b => b.Parameter).ToList(); UniquifyParameterNames(parameters); var functionPayload = new EdmFunctionPayload { ReturnParameters = new FunctionParameter[0], Parameters = parameters.ToArray(), IsComposable = false }; var function = databaseMapping.Database .AddFunction( (functionNamePrefix ?? entityTypeBase.Name) + "_" + modificationOperator.ToString(), functionPayload); var functionMapping = new ModificationFunctionMapping( entitySetBase, entityTypeBase, function, parameterBindings, null, resultProperties != null ? resultProperties.Select( p => new ModificationFunctionResultBinding( columnMappings.First(cm => cm.PropertyPath.SequenceEqual(new[] { p })).ColumnProperty.Name, p)) : null); return functionMapping; }
public void VisitFunction_visits_return_parameters() { var visitorMock = new Mock<EdmModelVisitor> { CallBase = true }; var returnParameter = new FunctionParameter( "r", TypeUsage.CreateDefaultTypeUsage( PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32)), ParameterMode.ReturnValue); var functionPayload = new EdmFunctionPayload { ReturnParameters = new[] { returnParameter } }; visitorMock.Object.VisitEdmFunction(new EdmFunction("f", "N", DataSpace.SSpace, functionPayload)); visitorMock.Verify(v => v.VisitFunctionReturnParameters(It.IsAny<IEnumerable<FunctionParameter>>()), Times.Once()); visitorMock.Verify(v => v.VisitFunctionReturnParameter(returnParameter), Times.Once()); }
private StorageModificationFunctionMapping GenerateFunctionMapping( ModificationOperator modificationOperator, EntitySetBase entitySetBase, EntityTypeBase entityTypeBase, DbDatabaseMapping databaseMapping, IEnumerable<EdmProperty> parameterProperties, IEnumerable<Tuple<StorageModificationFunctionMemberPath, EdmProperty>> iaFkProperties, IList<ColumnMappingBuilder> columnMappings, IEnumerable<EdmProperty> resultProperties = null) { DebugCheck.NotNull(entitySetBase); DebugCheck.NotNull(entityTypeBase); DebugCheck.NotNull(databaseMapping); DebugCheck.NotNull(parameterProperties); DebugCheck.NotNull(iaFkProperties); DebugCheck.NotNull(columnMappings); var useOriginalValues = modificationOperator == ModificationOperator.Delete; var parameterMappingGenerator = new FunctionParameterMappingGenerator(_providerManifest); var parameterBindings = parameterMappingGenerator .Generate( modificationOperator, parameterProperties, columnMappings, new List<EdmProperty>(), useOriginalValues) .Concat( parameterMappingGenerator .Generate(iaFkProperties, useOriginalValues)) .ToList(); FunctionParameter rowsAffectedParameter = null; var parameters = parameterBindings.Select(b => b.Parameter).ToList(); if (parameterBindings .Any( pb => !pb.IsCurrent && pb.MemberPath.AssociationSetEnd == null && ((EdmProperty)pb.MemberPath.Members.Last()).ConcurrencyMode == ConcurrencyMode.Fixed)) { rowsAffectedParameter = new FunctionParameter( "RowsAffected", _providerManifest.GetStoreType( TypeUsage.CreateDefaultTypeUsage( PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32))), ParameterMode.Out); parameters.Add(rowsAffectedParameter); } UniquifyParameterNames(parameters); var functionPayload = new EdmFunctionPayload { ReturnParameters = new FunctionParameter[0], Parameters = parameters.ToArray(), IsComposable = false }; var function = databaseMapping.Database .AddFunction( entityTypeBase.Name + "_" + modificationOperator.ToString(), functionPayload); var functionMapping = new StorageModificationFunctionMapping( entitySetBase, entityTypeBase, function, parameterBindings, rowsAffectedParameter, resultProperties != null ? resultProperties.Select( p => new StorageModificationFunctionResultBinding( columnMappings.First(cm => cm.PropertyPath.SequenceEqual(new[] { p })).ColumnProperty.Name, p)) : null); return functionMapping; }