从Mock Repository切换到Entity Framework不会显示任何产品 [英] Switching from Mock Repository to Entity Framework does not display any products

查看:78
本文介绍了从Mock Repository切换到Entity Framework不会显示任何产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读Pro ASP.NET MVC 5 - Adam Freeman

一书。在第7章中,构建了Sportstore应用程序,并且首先使用模拟存储库显示了产品到目前为止一切正常。



现在用实体框架替换真实的产品数据。我做了一切,如书中所说,添加真实NinjectDependencyResolver.cs文件中的存储库绑定,如第182页所示,但在运行时,它显示一个空白页。换句话说,它没有要显示的产品。



我迷路了,因为我不知道从哪里开始调试它。表肯定有数据。



请帮忙 - 我已经重新做了这个应用程序3次,我仍然得到相同的结果 - 非常感谢您的帮助

解决方案

除非您将代码片段粘贴到返回异常或空记录的位置,否则以下是 我们可以要求您遵循的步骤:



1:请调试并在控制器的操作上添加断点,以返回产品数据列表。



2:如果要返回数据,请在此处查看。



3:如果要返回数据,那么检查视图页面是否有IEnumerable模型。这样就可以通过 @foreach(模型中的var项目)访问数据列表



4.你还可以检查你的web.config连接字符串和你正在进行数据库操作的服务方法(如果有的话)。



如果有的话,回复你的查询。

谢谢。 :)

I am working through the Book "Pro ASP.NET MVC 5 - Adam Freeman
' . In chapter 7 the Sportstore application is built and the Products are first displayed with the Mock Repository on page 174. Everything works fine up to here.

Now this is to be replaced with the real Product data using Entity Framework. I did everything as the book says , Adding the Real Repository Binding in the NinjectDependencyResolver.cs File as on page 182, but when running it, it displays a blank page. In other words it does not have products to display.

I am lost as I do not know where to start debugging it. The table definitely does have the data in it.

Please help - I have re-done this application 3 times and I still get the same result - your assistance is highly appreciated

解决方案

Unless you paste your code snippet where the exception or empty record is returned then the below are the steps we can ask you to follow:

1: Please debug and add a breakpoint on the action of the controller that returns the products data list.

2: Check here if the data is being returned.

3: If data is being returned then check the view page if that has an IEnumerable of the model. So that the list of data can be accessed through @foreach(var item in model)

4. You can also check your web.config connection strings and the service method where you are doing the database operation(if any exception).

Post back your queries if any.
Thanks. :)


这篇关于从Mock Repository切换到Entity Framework不会显示任何产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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