What's the correct way to use ObjectResult wit

2020-05-04 23:22发布

问题:

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.
}