且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在实体框架中添加存储过程复杂类型

更新时间:2021-11-28 00:12:30

好的 - 这是执行此操作的分步方法:

OK - here's the step-by-step way of doing this:

(1) 将您的存储过程添加到 EDMX 文件中(当您第一次创建它时,或者稍后使用从数据库更新模型并选择该存储过程)

(1) add your stored procedure to the EDMX file (when you first create it, or later on by using Update model from database and picking that stored procedure)

(2) 一旦你的模型中有存储过程 - 使用 Model Browser 添加一个 Function Import :

(2) once you have the stored procedure in your model - use the Model Browser to add a Function Import :

(3) 弹出的下一个对话框非常重要 - 您需要 (1) 定义存储过程返回复杂类型的集合,然后您需要 (2) 从该存储过程中获取列信息以知道它将返回哪些列,然后 (3) 告诉 Visual Studio 根据该列信息生成一个新的复杂类型:

(3) the next dialog that pops up is vitally important - you need to (1) define that the stored procedure returns a collection of complex types, then you need to (2) get the column info from that stored procedure to know what columns it will return, then (3) you tell Visual Studio to generate a new complex type based on that column info:

(4) 完成后 - 您现在应该在模型浏览器的概念模型部分看到存储过程,并且新生成的复杂类型也应该显示在那里:

(4) once you've done that - you should now see the stored procedure in your conceptual model section in the Model Browser, and the newly generated complex type should show up there, too: