更改我的表名似乎与其他人不同。所以我决定对一个单独的项目进行测试,以澄清到目前为止我尝试过的事情。
数据库
错误消息
public class MyDB : DbContext
{
public MyDB()
: base("name=DefaultConnection") { }
//(1) protected override void OnModelCreating(DbModelBuilder modelBuilder)
//{
// //Changing Database table name to Metadata
// modelBuilder.Entity<Restaurant>()
// .ToTable("Restaurants2");
//}
//(2) protected override void OnModelCreating(DbModelBuilder modelBuilder)
//{
// modelBuilder.Entity<Restaurant>().ToTable("Restaurants2");
// // otherwise EF assumes the table is called "Products"
//}
//(3) protected override void OnModelCreating(DbModelBuilder modelBuilder)
//{
// modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
//}
public DbSet<Restaurant> Restaurants { get; set; }
public DbSet<RestaurantReview> Reviews { get; set; }
}
//[Table("Restaurants2")]
public class Restaurant
{
//[Column("Id")]
public int Id { get; set; }
//[Column("Name")]
public string Name { get; set; }
//[Column("City")]
public string City { get; set; }
//[Column("Country")]
public string Country { get; set; }
public ICollection<RestaurantReview> Reviews { get; set; }
}
public class RestaurantReview
{
public int Id { get; set; }
public int RestaurantId { get; set; }
public string Body { get; set; }
public int Rating { get; set; }
}
我真的不走运!我做错了什么?