[英]Calling Stored Procedure from Database Context generated by Entity Framework
I'm using C# + MVC 4 + MySQL and I want to call in my controller a method create by Entity Framework 5 to call a stored procedure. 我正在使用C#+ MVC 4 + MySQL,我想在控制器中调用由Entity Framework 5创建的方法来调用存储过程。
I do not know how to call in my controller the following method, create in .Context.cs
file, by Entity Framework: 我不知道如何在我的控制器中调用以下方法,由Entity Framework在
.Context.cs
文件中创建:
public virtual ObjectResult<getProductsListForHome_Result> getProductsListForHome(Nullable<int> inOffer, Nullable<int> categoryId)
{
var inOfferParameter = inOffer.HasValue ?
new ObjectParameter("inOffer", inOffer) :
new ObjectParameter("inOffer", typeof(int));
var categoryIdParameter = categoryId.HasValue ?
new ObjectParameter("categoryId", categoryId) :
new ObjectParameter("categoryId", typeof(int));
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<getProductsListForHome_Result>("getProductsListForHome", inOfferParameter, categoryIdParameter);
}
I already tried this: 我已经试过了:
//
// GET: /Products/
public ActionResult Index()
{
IEnumerable<getProductsListForHome_Result> products = db.getProductsListForHome(1, 14);
var test = string.Join(",", (object[])products.ToArray());
return Content(test);
}
And when I access /Products/ (the Index() method of Products' Controller) , I see a blank page with this: MyApp.Models.getProductsListForHome_Result . 当我访问/ Products /(产品的Controller的Index()方法)时 ,我看到一个空白页面: MyApp.Models.getProductsListForHome_Result 。
So I ask: what I have to do? 所以我问:我该怎么办?
将退货内容更改为退货视图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.