简体   繁体   中英

Is that possible to update multiple procedure and function definition in EDMX file C# DB first approach

I have to update many procs and function in edmx, and I don't want update 1 by 1 in Model browser and also don't want to re-create edmx, So is there any possible solution there, i can update multiple proc or function in edmx file in one go.

You can refer to the following to the followings to update multiple proc or function in one go.

First, please right click the edmx file and choose the update model from database .

在此处输入图像描述

Second, If you want to add the new procedures, you can click Add and choose the correspond stored procedure.

在此处输入图像描述

If you want to update the existed procedure, you can click Refresh and choose the stored procedure.

在此处输入图像描述

Third, you can see the correspond method in the dbcontext.cs file.

public virtual ObjectResult<TestProcedure_Result> TestProcedure(Nullable age) { var ageParameter = age.HasValue? new ObjectParameter("age", age): new ObjectParameter("age", typeof(int));

        return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<TestProcedure_Result>("TestProcedure", ageParameter);
    }

    public virtual ObjectResult<Pro1_Result> Pro1(Nullable<int> age)
    {
        var ageParameter = age.HasValue ?
            new ObjectParameter("age", age) :
            new ObjectParameter("age", typeof(int));

        return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<Pro1_Result>("Pro1", ageParameter);
    }

    public virtual ObjectResult<string> Proc2(Nullable<int> score)
    {
        var scoreParameter = score.HasValue ?
            new ObjectParameter("score", score) :
            new ObjectParameter("score", typeof(int));

        return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<string>("Proc2", scoreParameter);
}

Finally, you can use the following code to get the result by using the stored procedure.

 using (var db = new StudentContext())
            {
                var result = db.TestProcedure(20);
                foreach (var stu in result)
                {
                    Console.WriteLine(stu.Name);
                }
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM