Solved

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

Posted on 2014-03-20
8
1,153 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
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!

 

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 500 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Introduction In this tutorial, I'll explain how to create an animated progress meter in a wireframe prototype developed using Axure RP 7.0 - a leading prototyping tool for designing web sites and software. (For more information about Axure and gett…
Developer tools in browsers have been around for a while, yet they are still heavily underused by developers. Developers still fix html or CSS then refresh page to see effect, or they put alert or debugger in JavaScript and then try again and again …
This video teaches users how to migrate an existing Wordpress website to a new domain.
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…

749 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