What's the correct way to use ObjectResult with input parameters to StoredProcedure in Entity Framework? (Output mapped to Complex Type Property)

醉酒当歌 提交于 2019-12-20 06:19:48

问题


I have several listboxes which have a SelectedItem property I intend to use as input parameters to execute my stored procedure in Entity Framework.

I now realize my only hope for easily returning entity objects as the result of my Stored Procedure is to map the Stored Procedure (or Function Import) to a complex type which matches the output. (Used Julie Lerman's post here to make this decision.)

However, I need help using ObjectResult with EntityFramework to capture my listbox SelectedItem properties and feed them to the Stored Procedure (and thus output my complex type entities). Is anyone familiar with this process?

ANY help would be appreciated (guesses included). Please let me know if I can be more clear.


回答1:


You can access it as a function call, and the order of the parameters is determined by EF:

using (var db = new YourEntityContext())
{
    var result = db.YourFunctionImportName(
        Convert.ToInt32(ddlWhatever1.SelectedValue),
        Convert.ToInt32(ddlWhatever2.SelectedValue));

    //Int32 used as an example, use whatever type your function import is expecting.
    //Do whatever with result.
}


来源:https://stackoverflow.com/questions/11836345/whats-the-correct-way-to-use-objectresult-with-input-parameters-to-storedproced

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!