Solved

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

Posted on 2014-03-20
8
1,148 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Foolproof security solutions has become one of the key necessities of every e-commerce or Internet banking website. If you too own an online shopping site then its vital for you to equip your web portal with customer security features that can allow…
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…
This video teaches users how to migrate an existing Wordpress website to a new domain.
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…

786 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