C# 从实体框架生成的数据库上下文调用存储过程 目标
我正在使用C#+MVC4+MySQL,我想在我的控制器中调用Entity Framework 5创建的方法来调用存储过程 问题 我不知道如何在控制器中调用以下方法,按实体框架在C# 从实体框架生成的数据库上下文调用存储过程 目标,c#,sql,entity-framework,C#,Sql,Entity Framework,我正在使用C#+MVC4+MySQL,我想在我的控制器中调用Entity Framework 5创建的方法来调用存储过程 问题 我不知道如何在控制器中调用以下方法,按实体框架在.Context.cs文件中创建: public virtual ObjectResult<getProductsListForHome_Result> getProductsListForHome(Nullable<int> inOffer, Nullable<int> categor
.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);
}
公共虚拟对象结果getProductsListForHome(可为null的inOffer,可为null的categoryId)
{
var inOfferParameter=inOffer.HasValue?
新的ObjectParameter(“inOffer”,inOffer):
新的ObjectParameter(“inOffer”,typeof(int));
var categoryIdParameter=categoryId.HasValue?
新的ObjectParameter(“categoryId”,categoryId):
新的ObjectParameter(“categoryId”,typeof(int));
返回((IObjectContextAdapter)this.ObjectContext.ExecuteFunction(“getProductsListForHome”,inOfferParameter,categoryIdParameter);
}
我所拥有的
我已经试过了:
//
// GET: /Products/
public ActionResult Index()
{
IEnumerable<getProductsListForHome_Result> products = db.getProductsListForHome(1, 14);
var test = string.Join(",", (object[])products.ToArray());
return Content(test);
}
//
//获取产品/
公共行动结果索引()
{
IEnumerable products=db.getProductsListForHome(1,14);
var test=string.Join(“,”,(object[])products.ToArray();
返回内容(测试);
}
当我访问/Products/(Products'Controller的Index()方法)时,我会看到一个空白页面,上面写着:MyApp.Models.getProductsListForHome\u Result
所以我问:我必须做什么?将返回内容更改为返回视图。“未找到视图'MyApp.Models.getProductsListForHome\u Result'或其主视图,或者没有视图引擎支持搜索的位置。”您是否设置了接收实体模型的视图?