Error: The model backing the 'CompanyDBContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).
Watch solution on YouTube:
- error displayed once updated my context class
to resolve add the following to your Global.asax.cs file
using System.Data.Entity;
using MVCCrud.Models; // where MVCCrud is the name of my application
than in protected void Application_Start() add the following
Database.SetInitializer<CompanyDBContext>(new DropCreateDatabaseIfModelChanges<CompanyDBContext>());
where CompanyDBContext is the name of my context method
Tuesday, 15 April 2014
Thursday, 10 April 2014
MVC5 - Simple CRUD Example - Code First
Watch this example on YouTube
All details - how to create this project are in the YouTube movie above.
You will need to create Customer class in Model folder with the following code
using System.Web;
using System.Data.Entity;
namespace MVCCrud.Models
{
public class Customer
{
public int ID { get; set; }
public string Name { get; set; }
}
public class CompanyDBContext : DbContext
{
public DbSet<Customer> Customers { get; set; }
}
}
Also you will have to add the following code to web.config file
<add name="CompanyDBContext"
connectionString="Data Source=(LocalDB)\v11.0;
AttachDbFilename=|DataDirectory|\CompanyDB.mdf;
Integrated Security= True" providerName="System.Data.SqlClient" />
</connectionStrings>
All details - how to create this project are in the YouTube movie above.
You will need to create Customer class in Model folder with the following code
using System.Web;
using System.Data.Entity;
namespace MVCCrud.Models
{
public class Customer
{
public int ID { get; set; }
public string Name { get; set; }
}
public class CompanyDBContext : DbContext
{
public DbSet<Customer> Customers { get; set; }
}
}
Also you will have to add the following code to web.config file
<add name="CompanyDBContext"
connectionString="Data Source=(LocalDB)\v11.0;
AttachDbFilename=|DataDirectory|\CompanyDB.mdf;
Integrated Security= True" providerName="System.Data.SqlClient" />
</connectionStrings>
Tuesday, 8 April 2014
MVC5 - How to remove unused Usings
Watch this example on YouTube:
Rigth click file - select Organize Usings - than select Remove Unused Usings
Monday, 7 April 2014
MVC5 - How to change page title
Watch this example on YouTube:
Add the following code to cshtml file (inside Views folder)
@{
ViewBag.Title = "this is my title";
}
this works because my layout page has the following code:
<title>@ViewBag.Title - My ASP.NET Application</title>
Saturday, 5 April 2014
MVC5 - How to change startup page
Watch this example on YouTube
In solution explorer under App_Start folder open RouteConfig file
modify the following code
defaults: new { controller = "Start", action = "StartWithMe", id = UrlParameter.Optional }
replace "Start" with the name of the View folder
replace StartWithMe with the name of the method in selected controller
In solution explorer under App_Start folder open RouteConfig file
modify the following code
defaults: new { controller = "Start", action = "StartWithMe", id = UrlParameter.Optional }
replace "Start" with the name of the View folder
replace StartWithMe with the name of the method in selected controller
Subscribe to:
Posts (Atom)