Skip to content

Is InsertUsingStoredProcedure, UpdateUsingStoredProcedure, DeleteUsingStoredProcedure in model builder supported? #1158

Description

@Camel-RD

When i configure model with InsertUsingStoredProcedure and try to save changes, i get an error:
SQL error code = -104
Token unknown - line 1, column 1
CALL

Activity

  1. self-assigned this
    on Feb 12, 2024
  2. Camel-RD commented on Jul 10, 2024

    @Camel-RD
    ContributorAuthor

    Can we fix this issue with this code in FbUpdateSqlGenerator.cs?

    	public override ResultSetMapping AppendStoredProcedureCall(
    		StringBuilder commandStringBuilder,
    		IReadOnlyModificationCommand command,
    		int commandPosition,
    		out bool requiresTransaction)
    	{
    		var storedProcedure = command.StoreStoredProcedure;
    		var resultSetMapping = ResultSetMapping.NoResults;
    
    		foreach (var resultColumn in storedProcedure.ResultColumns)
    		{
    			resultSetMapping = ResultSetMapping.LastInResultSet;
    			if (resultColumn == command.RowsAffectedColumn)
    			{
    				resultSetMapping |= ResultSetMapping.ResultSetWithRowsAffectedOnly;
    			}
    			else
    			{
    				resultSetMapping = ResultSetMapping.LastInResultSet;
    				break;
    			}
    		}
    
    		commandStringBuilder.Append("EXECUTE PROCEDURE ");
    		SqlGenerationHelper.DelimitIdentifier(commandStringBuilder, storedProcedure.Name);
    
    		if (storedProcedure.Parameters.Any())
    		{
    			commandStringBuilder.AppendLine();
    			var first = true;
    
    			for (var i = 0; i < command.ColumnModifications.Count; i++)
    			{
    				var columnModification = command.ColumnModifications[i];
    				if (columnModification.Column is not IStoreStoredProcedureParameter parameter)
    				{
    					continue;
    				}
    
    				if (parameter.Direction.HasFlag(ParameterDirection.Output))
    				{
    					continue;
    				}
    
    				if (first)
    				{
    					first = false;
    				}
    				else
    				{
    					commandStringBuilder.Append(", ");
    				}
    				SqlGenerationHelper.GenerateParameterNamePlaceholder(
    					commandStringBuilder, columnModification.UseOriginalValueParameter
    						? columnModification.OriginalParameterName!
    						: columnModification.ParameterName!);
    			}
    		}
    
    		commandStringBuilder.AppendLine(SqlGenerationHelper.StatementTerminator);
    		requiresTransaction = true;
    		return resultSetMapping;
    	}
    
    
  3. cincuranet commented on Jul 15, 2024

    @cincuranet
    Member

    Can you create PR?

  4. linked a pull request that will close this issueAdded AppendStoredProcedureCall #1185on Nov 7, 2024
  5. added theissue type on Apr 11, 2025
  6. added this to the EFCore-vNext milestone on Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions