Solved

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

Posted on 2014-03-20
8
1,137 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
  • 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article provides a case study on how our local youth baseball league deployed a new website, including the platform selection, implementation and benefits to the league.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

747 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now