在实体框架中将ObjectResult与输入参数一起使用到StoredProcedure的正确方法是什么? (输出映射到复杂类型属性)

时间:2022-10-22 10:55:45

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

我有几个列表框,它有一个SelectedItem属性,我打算用它作为输入参数在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.)

我现在意识到我唯一希望轻松返回实体对象,因为我的存储过程的结果是将存储过程(或函数导入)映射到与输出匹配的复杂类型。 (使用Julie Lerman的帖子做出这个决定。)

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?

但是,我需要帮助使用ObjectResult和EntityFramework来捕获我的listbox SelectedItem属性并将它们提供给存储过程(从而输出我的复杂类型实体)。有人熟悉这个过程吗?

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

任何帮助将不胜感激(包括猜测)。如果我能更清楚,请告诉我。

1 个解决方案

#1


0  

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

您可以将其作为函数调用来访问,参数的顺序由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.}

#1


0  

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

您可以将其作为函数调用来访问,参数的顺序由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.}