I have followed the Tutorial for WingTip Toys. The only change that I made was that instead of using the word WingTipToys I used HuronWood.
I have created the complete tutoria and the Model folder my ProductContext.cs looks like this (note comment about connection string just added now)
using System.Data.Entity;
namespace HuronWood.Models
{
public class ProductContext : DbContext
{
public ProductContext()
: base("HuronWoodDatabase") //HuronWoodDatabase should be my Connection String
{
}
public DbSet<Category> Categories { get; set; }
public DbSet<Product> Products { get; set; }
public DbSet<CartItem> ShoppingCartItems { get; set; }
public DbSet<Order> Orders { get; set; }
public DbSet<OrderDetail> OrderDetails { get; set; }
}
}
However, my actual connections string in my Web.config file looked like this
The mistake of <add name="HuronWood" instead of HuronWoodDatabase meant that everything was going to the Default or database called aspnet-HuronWood-20121116192324 (I thought it was a wired name but there is a lot going on in these tutorials).
After I was done the tutorial I changed the Connection String to look like this
Model compatibility cannot be checked because the database does not contain model metadata. Model compatibility can only be checked for databases created using Code First or Code First Migrations.
What is happening is that my Membership tables get added to the LocalDBHuronWood but my Cateogory, Products, Cart, et tables do not get added. This error happens in when loading Default.aspx. The actual error occurs in ShoppingCartActions.cs in the routine
GetCount
jfeeney
Member
163 Points
551 Posts
Code First - Moving from localDB to Test Server
Nov 21, 2012 06:01 PM|LINK
I have followed the Tutorial for WingTip Toys. The only change that I made was that instead of using the word WingTipToys I used HuronWood.
I have created the complete tutoria and the Model folder my ProductContext.cs looks like this (note comment about connection string just added now)
using System.Data.Entity; namespace HuronWood.Models { public class ProductContext : DbContext { public ProductContext() : base("HuronWoodDatabase") //HuronWoodDatabase should be my Connection String { } public DbSet<Category> Categories { get; set; } public DbSet<Product> Products { get; set; } public DbSet<CartItem> ShoppingCartItems { get; set; } public DbSet<Order> Orders { get; set; } public DbSet<OrderDetail> OrderDetails { get; set; } } }However, my actual connections string in my Web.config file looked like this
<connectionStrings> <add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-HuronWood-20121116192324;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-HuronWood-20121116192324.mdf" /> <add name="HuronWood" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\huronwood.mdf;Integrated Security=True" providerName="System.Data.SqlClient " /> </connectionStrings>The mistake of <add name="HuronWood" instead of HuronWoodDatabase meant that everything was going to the Default or database called aspnet-HuronWood-20121116192324 (I thought it was a wired name but there is a lot going on in these tutorials).
After I was done the tutorial I changed the Connection String to look like this
<connectionStrings> <add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-HuronWood-20121116192324;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-HuronWood-20121116192324.mdf" /> <add name="HuronWoodDatabase" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\huronwood.mdf;Integrated Security=True" providerName="System.Data.SqlClient " /> </connectionStrings>This worked but it creates to databases. This won't work on my Shared Hosting Server and I only get 1 MSSQL database
I tried creating just one database by using these connections strings
<connectionStrings> <add name="DefaultConnection" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\LocalDBHuronWood.mdf;Integrated Security=True" providerName="System.Data.SqlClient" /> <add name="HuronWoodDatabase" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\LocalDBHuronWood.mdf;Integrated Security=True" providerName="System.Data.SqlClient " /> </connectionStrings>But I get the following error message
Model compatibility cannot be checked because the database does not contain model metadata. Model compatibility can only be checked for databases created using Code First or Code First Migrations.
What is happening is that my Membership tables get added to the LocalDBHuronWood but my Cateogory, Products, Cart, et tables do not get added. This error happens in when loading Default.aspx. The actual error occurs in ShoppingCartActions.cs in the routine GetCount
Thanks for your help, John
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Code First - Moving from localDB to Test Server
Nov 22, 2012 05:48 AM|LINK
Hello,
Maybe you have to re-create another new database with tables inside again to cope with the problem: