0

In the EF tutorials described the work with Model-First approach in the following way:

  1. create the model
  2. generate database sql from model
  3. launch generated sql via studio

But how it could be delivered to the customers? The database must be created on customers side automatically on program launch and it must be deleted when the customer select some menu action. How above behavior could be implemented via EF?

AeroSun
  • 2,401
  • 2
  • 23
  • 46
  • You could have a look at Automatic Code First Migrations. This should fulfill your needs: https://msdn.microsoft.com/en-us/data/jj554735.aspx – schlonzo Mar 31 '16 at 11:48
  • Does Model-first mean you have an EDMX file? – H H Mar 31 '16 at 12:03

1 Answers1

2

Your Model-First approach should have create a DbContext derived class, something like class MyModelContainer : DbContext.

In the startup phase of your app, do something like this:

using(var ctx = new MyModelContainer())
{
   ctx.Database.CreateIfNotExists();
}

similarly, when you want to delete it (first close all connections):

using(var ctx = new MyModelContainer())
{
   ctx.Database.Delete();
}
H H
  • 263,252
  • 30
  • 330
  • 514