Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Entity Framework - SportsStore - Book ASP.NET MVC 4 - Chapter7 not showing products

Posted on 2014-03-20
8
Medium Priority
?
1,188 Views
Last Modified: 2014-03-28
I am trying to follow example in the book under section "creating the product repository" on Page 182. The problem that I am facing is the View is not listing any products, I have added products as per sample code into products table but the view is not showing anything.

Product class

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace SportsStore.Domain.Entities
{

 public class Product
    {
        public int ProductID { get; set; }

        public string Name { get; set; }
        public string Description { get; set; }
        public decimal Price { get; set; }
        public string Category { get; set; }
    }
}


Ninject Bindings

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Ninject;
using SportsStore.Domain.Entities;
using SportsStore.Domain.Abstract;
using Moq;
using SportsStore.Domain.Concrete;
using System.Data.Entity;

namespace SportsStore.WebUI.Infrastructure
{
    public class NinjectControllerFactory :DefaultControllerFactory
    {

        private IKernel ninjectKernel;

        public NinjectControllerFactory()
        {
            ninjectKernel = new StandardKernel();
            AddBindings();
        }

        protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
        {
            return controllerType == null ? null :  (IController) ninjectKernel.Get(controllerType);
        }

        private void AddBindings()
        {

            ninjectKernel.Bind<IProductsRepository>().To<EFProductRepository>();

        }
    }
}


Product Repository

using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SportsStore.Domain.Abstract;
using SportsStore.Domain.Entities;

namespace SportsStore.Domain.Concrete
{
    public class EFProductRepository : IProductsRepository
    {

        private EFDbContext context = new EFDbContext();

        public IQueryable<Product> Products
        {
            get { return context.Products; }
        }
    }
}


Connection String
<add name="EFDbContext"
      connectionString=
      "Data Source=(LocalDb)\v11.0;Initial Catalog=SportsStore;  
      Integrated Security=True"
      providerName="System.Data.SqlClient" />
0
Comment
Question by:cshark247
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 23

Expert Comment

by:Ioannis Paraskevopoulos
ID: 39955621
Hi,

A few suggestions to help you get a proper answer. As you may understand, not all of us have the mentioned book, so it is nearly impossible to figure what is wrong. We do not have sample data and we do not have the code of your view, so we cannot know what is wrong with it.

I would suggest you package your project and upload it somewhere providing the link here (I think EE allows you to upload projects and relative files here, but you may choose another media such as dropbox????).

I think this would be the first step to get you closer to an answer.

Giannis
0
 

Author Comment

by:cshark247
ID: 39957223
Thanks for your suggestion, the link below contains all the project files.

https://www.dropbox.com/s/hdas6kcrmauadvh/SportsStore.zip
0
 
LVL 23

Expert Comment

by:Ioannis Paraskevopoulos
ID: 39957397
Just checked your project.

In the folder SportsStore there is a file called dbo.Products.data.sql. Open your SQL Server Management Studio. In the connection put (localDB)\v11.0 and choose windoe=ws authendication and login.

There expand DataBases, right click on SportsStore and choose New Query. In the pane that will open copy and paste the contents of the file. If you hit F5 you will get an error saying there is no column ProductIDid. Rename all ProductIDid to ProductID and hit F5.

Now you have your product table filled with data. Now run your project and happy learning ;-)....

Giannis
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 

Author Comment

by:cshark247
ID: 39957668
when u say copy and paste contents of file, does it means write insert statement to fill data? please explain.


Thanks

cshark247
0
 
LVL 23

Accepted Solution

by:
Ioannis Paraskevopoulos earned 2000 total points
ID: 39958164
Yes. Alternatively you may double click the file. It will open sql server management studio. Make sure you are connected in the right db, change ProductIDid to ProductId and run.
0
 

Author Comment

by:cshark247
ID: 39962221
on connecting to database it has prodictId not ProductIDid as field name. However I found that there are 2 database and when I deleted duplicate database it started working.

Thanks for your help. I really appreciate it.
0
 

Author Closing Comment

by:cshark247
ID: 39962242
I really appreciate "jyparask" for all his effort to help me solve the problem.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question