Most of the seed data is used for develpment purposes only. All develompent data should not bring to production. The seed can be used to production if you really have data use on both development and production. If you don't have data to bring to production,
just remove the seed or all the initializer. Example commented the SetInitializer like the following code at Global.asax.cs:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
// Use LocalDB for Entity Framework by default
Database.DefaultConnectionFactory = new SqlConnectionFactory("Data Source=(localdb)\v11.0; Integrated Security=True; MultipleActiveResultSets=True");
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
BundleTable.Bundles.RegisterTemplateBundles();
//Database.SetInitializer<SchoolContext>(new SchoolInitializer());
}
Ok, thanks was kinda expecting that answer but wanted it to be verified.
As for updating the Production database would I just change the Connection string to the Production SQL server from my project and run Update-Database?
Ok, so another question is. I've created my DEV SQL db that i've been doing my testing on. When going to production, should I just run the update-database with the production connection string to create the database on the production server or should you
copy over your development database to the production side.
In this instance its a totally new site with no production side yet.
Before you go to production, to make you really sure, try in development again using diffrent database name, and at your initilizer remove all the seed method, should only contain like this code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using ContosoUniversity.Models;
namespace ContosoUniversity.DAL
{
public class SchoolInitializer : DropCreateDatabaseIfModelChanges<SchoolContext>
{
// THERE IS SHOULD NO MORE SEED HERE
}
}
After you rerun the project with the new database name, try to create a raw in your table using your project, then check the new database has been created or not. If exist, the go to production change all the necessary things.
Jannen Siahaan
Indonesian Humanitarian Foundation
Marked as answer by MasterV23 on May 12, 2012 03:28 PM
MasterV23
Member
113 Points
318 Posts
EF 4.3 running Update-Database don't run seed data.
May 10, 2012 03:44 PM|LINK
Is it possible to not have it run the seed data for say a production / live server?
jsiahaan
Contributor
2322 Points
596 Posts
Re: EF 4.3 running Update-Database don't run seed data.
May 10, 2012 11:00 PM|LINK
Hi,
Most of the seed data is used for develpment purposes only. All develompent data should not bring to production. The seed can be used to production if you really have data use on both development and production. If you don't have data to bring to production, just remove the seed or all the initializer. Example commented the SetInitializer like the following code at Global.asax.cs:
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); // Use LocalDB for Entity Framework by default Database.DefaultConnectionFactory = new SqlConnectionFactory("Data Source=(localdb)\v11.0; Integrated Security=True; MultipleActiveResultSets=True"); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); BundleTable.Bundles.RegisterTemplateBundles(); //Database.SetInitializer<SchoolContext>(new SchoolInitializer()); }Hope this can help.
Indonesian Humanitarian Foundation
MasterV23
Member
113 Points
318 Posts
Re: EF 4.3 running Update-Database don't run seed data.
May 10, 2012 11:16 PM|LINK
Ok, thanks was kinda expecting that answer but wanted it to be verified.
As for updating the Production database would I just change the Connection string to the Production SQL server from my project and run Update-Database?
jsiahaan
Contributor
2322 Points
596 Posts
Re: EF 4.3 running Update-Database don't run seed data.
May 10, 2012 11:27 PM|LINK
Yes,
Absolutlely yes, you need to update the connectionString to production SQL server.
Have fun
Indonesian Humanitarian Foundation
MasterV23
Member
113 Points
318 Posts
Re: EF 4.3 running Update-Database don't run seed data.
May 11, 2012 12:27 PM|LINK
Ok, so another question is. I've created my DEV SQL db that i've been doing my testing on. When going to production, should I just run the update-database with the production connection string to create the database on the production server or should you copy over your development database to the production side.
In this instance its a totally new site with no production side yet.
jsiahaan
Contributor
2322 Points
596 Posts
Re: EF 4.3 running Update-Database don't run seed data.
May 11, 2012 12:54 PM|LINK
Hi,
So far so good.
Before you go to production, to make you really sure, try in development again using diffrent database name, and at your initilizer remove all the seed method, should only contain like this code.
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data.Entity; using ContosoUniversity.Models; namespace ContosoUniversity.DAL { public class SchoolInitializer : DropCreateDatabaseIfModelChanges<SchoolContext> { // THERE IS SHOULD NO MORE SEED HERE } }After you rerun the project with the new database name, try to create a raw in your table using your project, then check the new database has been created or not. If exist, the go to production change all the necessary things.
Indonesian Humanitarian Foundation
MasterV23
Member
113 Points
318 Posts
Re: EF 4.3 running Update-Database don't run seed data.
May 11, 2012 01:22 PM|LINK
Well since I'm using EF 4.3 migration my all the seeding is done in my Configurations. Thanks for the help but I've figured it out.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: EF 4.3 running Update-Database don't run seed data.
May 12, 2012 12:29 AM|LINK
Congratulation!Welcome to our forum next time to share us your nice suggestions as well as ideas,or chat with us about the technology……
Regaurds!