0

I've just started to learn ASP.Net MVC and Entity Framework using some tutorial and I have a problem.

I created class for Database Connection OdeToFoodDb.cs

using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;

namespace OdeToFood.Models
{
    public class OdeToFoodDb : DbContext
    {
        public DbSet<Restaurant> Restaurants { get; set; }
        public DbSet<RestaurantReview> Reviews { get; set; }
    }
}

and two classes Restaurant.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace OdeToFood.Models
{
    public class Restaurant
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string City { get; set; }
        public string Country { get; set; }
        public ICollection<RestaurantReview> Review { get; set; }
    }
}

and RestaurantReview.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace OdeToFood.Models
{
    public class RestaurantReview
    {
        public int Id { get; set; }
        public int Rating { get; set; }
        public string Body { get; set; }
        public int RestaurantId { get; set; }
    }
}

Then I try Add Connection enter image description here

enter image description here

And I've got database but it doesn't contain tables RestaurantReviews or Restaurants

enter image description here

but my tutorial says that I get these tables automatically. What I did wrong? How to make it create tables I need?

3
  • Can you post link to your tutorial? Commented Nov 9, 2015 at 9:42
  • No, I can't, it's video tutorial Building Applications with ASP.NET MVC 4 from pluralsight.com.
    – Heidel
    Commented Nov 9, 2015 at 9:48
  • 1
    Did you run your demo app?
    – Milen
    Commented Nov 9, 2015 at 10:01

1 Answer 1

1

In your Package Manager Console, run the following command

Update-Database -ProjectName <YourProject.DataLayer>

Check if your connection string is pointing to your expected database

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.