3

I'm trying to add some functionality to an application I'm writing, where the user can create a new Project, which has it's own database. When this is done, the previous Project database is to be exported to a .sql file that I can import and review later. Problem is, I can't see a way to export it. I've tried looking for a method to do so using:

using (var context = new DBContext())
{
    context.Database. // no method here for export
}

Is there a way inside of entity to export the database to a .sql file?

PiousVenom
  • 6,888
  • 11
  • 47
  • 86

1 Answers1

3

The short answer is No. It is not possible to do that through entity framework since there are many DB objects such as trigger or check constraint and properties like description which are not captured by EF.

However, you can use other tools such as SMO

Alireza
  • 10,237
  • 6
  • 43
  • 59
  • No problem. I will look into the link now. – PiousVenom Oct 01 '13 at 19:11
  • I'm still new to Entity and complex actions with databases as a whole, so forgive me if this is a silly question, but is it possible/feasible to use a stored procedure to do the export to a .sql file? – PiousVenom Oct 01 '13 at 19:15
  • @MyCodeSucks It is Entity Framework not Entity :). I googled it and reached a couple of interesting solutions for example: http://stackoverflow.com/questions/706664/generate-sql-create-scripts-for-existing-tables-with-query – Alireza Oct 01 '13 at 19:23