简体   繁体   English

是否可以在 EDMX 文件 C# DB 第一方法中更新多个程序和 function 定义

[英]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.我必须在 edmx 中更新许多 procs 和 function,我不想在 Model 浏览器中逐一更新,也不想重新创建 edmx,所以那里有任何可能的解决方案,我可以更新多个 proc 或function 在一个 go 中的 edmx 文件中。

You can refer to the following to the followings to update multiple proc or function in one go.您可以参考以下内容在一个 go 中更新多个 proc 或 function。

First, please right click the edmx file and choose the update model from database .首先,请右键单击 edmx 文件并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.第三,可以在dbcontext.cs文件中看到对应的方法。

public virtual ObjectResult<TestProcedure_Result> TestProcedure(Nullable age) { var ageParameter = age.HasValue?公共虚拟 ObjectResult<TestProcedure_Result> TestProcedure(Nullable age) { var ageParameter = age.HasValue? new ObjectParameter("age", age): new ObjectParameter("age", typeof(int)); 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);
                }
            }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用实体框架 6 db 第一种方法与 Oracle DB 动态更改 edmx 文件中的模式名称 - change schema name at edmx file dynamically using entity framework 6 db first approach with Oracle DB C#Edmx-更新数据库 - C# Edmx - update a database 如何在 c# ef5 db first 方法中使用 IntersectionTable 更新实体? - How to update entity with IntersectionTable in c# ef5 db first approach? 如何首先从另一个项目 c# 数据库中的数据模型 edmx 更新实体 - How to update entities from data model edmx in another project c# database first 带有实体框架错误的C#Mysql-无法更新EDMX文件 - C# Mysql with Entity Framework Error - Can't update EDMX File 实体框架-手动更新到edmx文件并被数据库更新覆盖 - Entity Framework - Manual Updates to edmx file overwritten with DB update 如何在C#项目中更新未由EDMX导入的表 - How to update table not imported by EDMX in C# project 使用C#和存储过程将文本文件解析并加载到DB中 - parse and load text file into DB using C# and Stored Procedure 哪个功能/模块在数据库第一个方法中生成.edmx文件? - Which function/module generates .edmx file in database first apporach? C#递归函数方法? - C# Recursive function approach?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM