存储过程到实体框架模型中 [英] Stored procedure into Entity Framework model

查看:72
本文介绍了存储过程到实体框架模型中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以将存储过程添加到Entity Framework模型( Model.edmx )吗?



我只是这样做是在Visual Studio 2010中完成的(除了我的存储过程现在不在添加选项卡上并且在刷新选项卡中)





我的存储过程是一个简单的 SELECT 语句,带有1个参数。



VS2010似乎已将其添加到模型中,但是我不知道它在哪里以及如何使用它? / p>

我在图中的任何地方或 Model.designer.cs

$ b中都看不到它$ b

解决方案

您分开了。这是一个隐藏的过程,需要多步骤。您必须通过在上面显示的菜单中选择存储过程,将它们包括在模型中。



完成后,您想查看模型浏览器





然后在模型浏览器中找到模型存储(其中将包含表/视图之类的文件夹)。右键单击您的存储过程,然后选择添加函数导入。





完成此操作后,您可以映射从SP返回的实体。





您将能够以强类型方式通过代码中的上下文访问实体。希望有帮助。


Can you add a stored procedure into an Entity Framework model (Model.edmx)?

I just did it in Visual Studio 2010, like this (except my stored procedure is now off the Add tab and is in the Refresh tab)

My stored procedure is a simple SELECT statement, taking 1 parameter.

VS2010 seems to have added it into the Model, but I wonder where it is and how I can use it?

I can't see it anywhere in the diagram nor in Model.designer.cs

解决方案

You part the way there. It's a bit of a hidden process and multi-stepped. You have to include the Stored Procedures in your model by selecting them in the menu you have shown above.

Once you have done that you want to view the 'Model Browser'

Then in the Model Browser, find the Model Store (This will have folders like 'Tables / Views'). Right click on your Stored Procedure and select 'Add Function Import'.

Once you have done this, you can map the Entities you will get back from your SP.

You will then be able to access your entities via your Context in code, in a strongly typed way. Hope that helps.

这篇关于存储过程到实体框架模型中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆