Why is there no Mysql Stored Procedure Parameter in the collection?

c# entity-framework mysql stored-procedures

Question

Mysql and entity framework are giving me trouble. With this response, I was able to resolve the issue with entity framework function arguments.

However, I have a stored process in mysql that I may use to add some data.

Parameter 'kick_Prod_StateID' not found in the collection.

C# has an error.

My method is as follows:

CREATE  PROCEDURE CreateState_(

    IN kick_Prod_StateID INT(11),
    IN kick_ShortName VARCHAR(3),
    IN kick_StateName VARCHAR(50)
)

BEGIN INSERT INTO State_
(
    Prod_StateID_,
    ShortName_,
    StateName_
)
VALUES 
( 
    kick_Prod_StateID ,
    kick_ShortName ,
    kick_StateName
) ; 
END$$

and entity framework generated the following C# code:

public ObjectResult<State_> AddState(Nullable<global::System.Int32> prod_StateID_, global::System.String shortName_, global::System.String stateName_)
    {
        ObjectParameter prod_StateID_Parameter;
        if (prod_StateID_.HasValue)
        {
            prod_StateID_Parameter = new ObjectParameter("Prod_StateID_", prod_StateID_);
        }
        else
        {
            prod_StateID_Parameter = new ObjectParameter("Prod_StateID_", typeof(global::System.Int32));
        }

        ObjectParameter shortName_Parameter;
        if (shortName_ != null)
        {
            shortName_Parameter = new ObjectParameter("ShortName_", shortName_);
        }
        else
        {
            shortName_Parameter = new ObjectParameter("ShortName_", typeof(global::System.String));
        }

        ObjectParameter stateName_Parameter;
        if (stateName_ != null)
        {
            stateName_Parameter = new ObjectParameter("StateName_", stateName_);
        }
        else
        {
            stateName_Parameter = new ObjectParameter("StateName_", typeof(global::System.String));
        }

        return base.ExecuteFunction<State_>("AddState", prod_StateID_Parameter, shortName_Parameter, stateName_Parameter);
    }

The line contains an error:

return base.ExecuteFunction<State_>("AddState", prod_StateID_Parameter, shortName_Parameter, stateName_Parameter);

How can I fix this issue?

Thx

1
1
5/23/2017 12:21:13 PM

Accepted Answer

I came up with a solution.

Stored procedure parameters were the issue.

The table and value arguments should have the same names when using mysql and entity framework together.

I suggest that the stored process be:

CREATE  PROCEDURE CreateState_(

IN Prod_StateID_ INT(11),
IN ShortName_ VARCHAR(3),
IN StateName_ VARCHAR(50)
)

BEGIN INSERT INTO State_
(
Prod_StateID_,
ShortName_,
StateName_
)
VALUES 
( 
Prod_StateID_ ,
ShortName_ ,
StateName_
) ; 
END$$
1
1/23/2012 10:27:18 AM

Popular Answer

Another option is to use edmx to add or delete material, such as the character "p_" or characters like "kick_" in your example.

make sure that the parameter names in the edmx function and the stored procedure stay the same. Make them the same if they are different.

Procedure in MySql:


CREATE CommentsDelete(TCommentId int)
BEGIN

delete from SmComment where Commentid in
(
select commentid from smcomment where parentid= TCommentId or commentid=TCommentId;
);
END

When Edmx First Invented This Function:

public int CommentsDelete(Nullable<global::System.Int32> p_CommentId)
        {
            ObjectParameter p_CommentIdParameter;
            if (p_CommentId.HasValue)
            {
                p_CommentIdParameter = new ObjectParameter("p_CommentId", p_CommentId);
            }
            else
            {
                p_CommentIdParameter = new ObjectParameter("p_CommentId", typeof    (global::System.Int32));
            }

            return base.ExecuteFunction("RecursiveCommentsDelete", p_CommentIdParameter);
        }

I changed "p CommentId" to "TCommentId," and now this is functioning well for me.

The Edmx Designer's role is:

public int CommentsDelete(Nullable<global::System.Int32> p_CommentId)
        {
            ObjectParameter p_CommentIdParameter;
            if (p_CommentId.HasValue)
            {
                p_CommentIdParameter = new ObjectParameter("TCommentId", p_CommentId);
            }
            else
            {
                p_CommentIdParameter = new ObjectParameter("TCommentId", typeof    (global::System.Int32));
            }

            return base.ExecuteFunction("RecursiveCommentsDelete", p_CommentIdParameter);
        }


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow