• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1200
  • Last Modified:

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

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
cshark247
Asked:
cshark247
  • 4
  • 3
1 Solution
 
Ioannis ParaskevopoulosCommented:
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
 
cshark247Author Commented:
Thanks for your suggestion, the link below contains all the project files.

https://www.dropbox.com/s/hdas6kcrmauadvh/SportsStore.zip
0
 
Ioannis ParaskevopoulosCommented:
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
Independent Software Vendors: 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!

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


Thanks

cshark247
0
 
Ioannis ParaskevopoulosCommented:
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
 
cshark247Author Commented:
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
 
cshark247Author Commented:
I really appreciate "jyparask" for all his effort to help me solve the problem.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now