在实体框架中将ObjectResult与输入参数一起用于StoredProcedure的正确方法是什么? (输出映射到复杂类型属性) [英] What's the correct way to use ObjectResult with input parameters to StoredProcedure in Entity Framework? (Output mapped to Complex Type Property)

查看:68
本文介绍了在实体框架中将ObjectResult与输入参数一起用于StoredProcedure的正确方法是什么? (输出映射到复杂类型属性)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个列表框,这些列表框具有SelectedItem属性,打算用作输入参数来执行我在Entity Framework中的存储过程.

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

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

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

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

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.

推荐答案

您可以将其作为函数调用来访问,并且参数的顺序由EF确定:

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

这篇关于在实体框架中将ObjectResult与输入参数一起用于StoredProcedure的正确方法是什么? (输出映射到复杂类型属性)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆