Heidel
Heidel

Reputation: 3254

Entity Framework doesn't create tables in Database

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?

Upvotes: 0

Views: 1063

Answers (1)

Pedro Benevides
Pedro Benevides

Reputation: 1980

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

Upvotes: 1

Related Questions