我使用ADO.Net DataServices將實體數據模型公開到Silverlight。該模型有一個返回void的存儲過程。我想從Silverlight客戶端調用此過程。在ADO.Net中執行存儲過程實體框架DataService
我的理解是,我應該爲DataService類添加一個[WebInvoke]方法,並使用DbCommand來調用存儲過程。
這裏是我到目前爲止的代碼:
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.
}
}
}
有人可以確認這是正確的做法,並顯示在這種情況下使用的DbCommand的例子嗎?
有意義
然後你就可以從瀏覽器中調用它。我從EF模型和DataServices開始,因爲我認爲存儲過程得到了完全支持。原來,只有在返回實體類型時才支持它們。請參閱:http://stackoverflow.com/questions/578536/function-imports-in-entity-model-with-a-non-entity-return-type – 2009-02-25 18:35:51