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.
- i have database 4 tables "restaurants" , "restaurants2" has same structure
- i started new mvc 4 project "internet application" being selected
- created 3 class
database
error message
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; } }
- firstly if @ code while ignoring comments started of project initially. , works can see restaurant data being display.
- my aim display tables "restaurants2" using same entity, did added attribute etc. [table("restaurants2")] restaurant class. gave me error.
- ive commented out attributes in restaurant class , used "(1) onmodelcreating" function, gave me same error
- then try second "(2) onmodelcreating" function , still gave me same error
- i went initial state started off beginning , change "restaurant" class name "restaurants2" still gave me same error
- i used third "(3) onmodelcreating" function hoping doesn't pluralize table name , still gave me same error.
i out of luck!!! doing wrong?
Comments
Post a Comment