There are times where you want to use a stored procedure that doesn’t return just normal rows out of a database. One classic example is if you are doing Full-Text Searching and want to return the Rank.
The first step to doing this is the get your stored procedures exposed in the ADO.NET Entity Data Model. Instead of going through the steps for doing that here, I’ll just point you to a great post by Julie Lerman on her blog: Implement SELECT Stored Procedures that return miscellaneous data in CTP2 of EF Designer.
After following those steps, you will have the stored procedures all ready to be called from the Entity Data Model. You can then use these stored procedures from ASP.NET, ASP.NET MVC, or anything else that can consume the Entity Data Model.
One side note, if you use the “Update Model from Database…” feature on your Entity Model, it will destroy the store layer tables that you created from Julie’s post. If that happens, just recreate them again.
Now to get this to work from Silverlight using RIA, there is another step that needs to be done. You need to get these stored procedures exposed in your Domain Service. One way to handle doing that is to create functions in the Domain Service like the following for each of them. Assume you have a stored procedure called SearchData and it takes a string as input to seach for in the database. You can create a function in the Domain Service like:
When you compile this, it will create a client side function called LoadSearchData that takes a string as input. Then you can call this just like you load any other data in Silverlight RIA:
Notice that I am hooking up to when the context is finished being loaded so that I know the data has been populated.