【发布时间】:2013-06-08 17:19:23
【问题描述】:
目标
我想在我的视图中显示存储过程的结果。
问题
Entity Framework 自动为我导入了一个执行过程的方法,但是我没有得到我期望在屏幕上显示的结果。
导入的函数是:
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);
}
我已经尝试过的
在 ProductsController 上:
//
// GET: /Products/
public ActionResult Index()
{
ObjectResult<getProductsListForHome_Result> products = db.getProductsListForHome(1, 14);
return View(products.ToList());
}
使用前面的代码,当我访问 http://myapp.com/Products/ 时,我收到以下消息:
传入字典的模型项是类型 'System.Collections.Generic.List
1[MyApp.Models.getProductsListForHome_Result]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1[MyApp.Models.bm_products]'。
我该怎么做才能解决这个问题?
【问题讨论】:
-
你需要知道的都在错误信息中,你应该能从错误信息中弄清楚。
-
你好,@DGibbs。感谢您的提示(?),但我是初学者,我仍然不能用自己的脚走路,所以我请求帮助。
标签: c# mysql entity-framework stored-procedures entity-framework-5