Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
996 views
in Technique[技术] by (71.8m points)

visual studio 2010 - Stored procedure into Entity Framework model

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)

VS screenshot

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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'

pic of 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'.

pic of context menu for function import

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

pic of function import dialog

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...