entity framework - EF - Changing table name not working -


changing table names doesn't seem working different. decided test on separate project clarify i've tried far.

  1. i have database 4 tables "restaurants" , "restaurants2" has same structure
  2. i started new mvc 4 project "internet application" being selected
  3. created 3 class

database

enter image description here

error message

enter image description here code

public class mydb : dbcontext {     public mydb()         : base("name=defaultconnection") { }     //(1) protected override void onmodelcreating(dbmodelbuilder modelbuilder)     //{     //    //changing database table name metadata     //    modelbuilder.entity<restaurant>()     //        .totable("restaurants2");     //}     //(2) protected override void onmodelcreating(dbmodelbuilder modelbuilder)     //{     //    modelbuilder.entity<restaurant>().totable("restaurants2");     //    // otherwise ef assumes table 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; } } 
  1. firstly if @ code while ignoring comments started of project initially. , works can see restaurant data being display.
  2. my aim display tables "restaurants2" using same entity, did added attribute etc. [table("restaurants2")] restaurant class. gave me error.
  3. ive commented out attributes in restaurant class , used "(1) onmodelcreating" function, gave me same error
  4. then try second "(2) onmodelcreating" function , still gave me same error
  5. i went initial state started off beginning , change "restaurant" class name "restaurants2" still gave me same error
  6. i used third "(3) onmodelcreating" function hoping doesn't pluralize table name , still gave me same error.

i out of luck!!! doing wrong?


Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -