I am using ADO.Net DataServices to expose an Entity Data Model to Silverlight. The model has a stored procedure that returns void. I want to call this procedure from the Silverlight client.
My understanding is that I should add a [WebInvoke] method to the DataService class and use DbCommand to call the stored procedure.
Here is my code so far:
using System.Data.Common; using System.Data.Services; using System.ServiceModel.Web; namespace Foo.Web { public class PayrollDataService : DataService<Foo.Web.PayrollEntities> { public static void InitializeService(IDataServiceConfiguration config) { config.SetEntitySetAccessRule('*', EntitySetRights.AllRead); config.UseVerboseErrors = true; } [WebInvoke] public void RunMyProcedure() { DbConnection conn = this.CurrentDataSource.Connection; DbCommand cmd = conn.CreateCommand(); // TODO: Call the stored procedure in the EF Data Model. } } }
Can someone confirm that this is the right approach and show an example using DbCommand in this situation?
The question I have is why you are running this in the Entity Framework, as you are returning nothing, which suggests to me you are not actually filling objects. If this is merely some clean up and does not affect the data, I would not have it in EF.
There is nothing wrong with using DBCommand to fire queries, if that is your question. And if you are actually affecting EF objects, I would not be as concerned about storing the procedure there. If the procedure does not affect EF objects, I would have it separate from EF rather than see everything as a nail and EF as the hammer.