0

I am new to EF Code first with MVC

I am looking deployment script for my project in various environments, QA, UAT and Production.

Is there any way i can develped script to deply in by one click. I've Models in seperate project.

Please share you thoughts.

2 Answers 2

1

Please clear the question. Following are my assumption as you facing problem in deploying EF MVC Code First application

To deployed website on QA, UAT or production server, Build Publish of the project and configure it in IIS. As you are using EF Code first approach once website will run it will create database at given location that is provided by you in web.config file.

To work website properly you have to create default data in Seed method of Configuration.cs

Sign up to request clarification or add additional context in comments.

Comments

0

You can use Seed method in your DbInitializer

public class YourInitializer: DropCreateDatabaseAlways<YourDbContext>
{
   protected override void Seed(YourDbContext context)
   {
      YourEntity entity = new YourEntity();
      context.YourDbSet.AddOrUpdate(entity);
      context.SaveChanges();
      base.Seed(context);
   }
}

You can use more Initializer types... explained here: http://www.codeguru.com/csharp/article.php/c19999/Understanding-Database-Initializers-in-Entity-Framework-Code-First.htm

Another solution is write your own powershell script, that connects to your database and make changes. This powershell script you can fire on build server etc.

If you want to change behavior on various servers, you can create some configuration attribute using Web.Config / App.Config (section appSettings).

1 Comment

Thanks Muhammad and Miroslav, I've seed method in Initializer, but it never got called, which is under Models project. namespace Models { public class MyInitializer : System.Data.Entity.CreateDatabaseIfNotExists<MyContext> { protected override void Seed(MyContext context){ } } } I don't know, why it's not calling. It does create database and tables without any data in it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.