2

Currently I use Visual Studio Database Project, so I can deploy changes to database with one click and keep data in database.

Now I want to be able to create model in Entity Framework and deploy with one click.

So I got sql script to create database from Entity Framework. I can run this script to create database, but I want to keep my data in database.

Is there any way to do that ? Any tool that will do that ? Should I generate it on my own with T4 ?

I use CI so I need to be able to deploy often. I want something similar to Visual Studio Database Project deployment, but with Entity Framework generated database.

3
  • @ Arran : In this case I use Visual Studio
    – rumburak
    Oct 5, 2012 at 13:52
  • Have you considered generating your model from your database? You would still be able to deploy your database as you do now, and would be able to update your model with a couple of clicks
    – Dan
    Oct 5, 2012 at 14:19
  • @ dskh : I want sql from model and not model from sql. I want to edit model. The thing that You are talking about is the thing I have now.
    – rumburak
    Oct 5, 2012 at 14:28

2 Answers 2

2

Liquibase is a database change management tool. It's implemented in Java but a command-line version is available to control your database upgrades (.NET version is under development).

If you need some modelling tool support then Power architect can be used with liquibase.

The problems associated with managing database schema upgrades are subtle. For some background reading I would recommend:

Update

Create a file called liquibase.properties to hold the database details:

url=jdbc:sqlserver://localhost:1433;databaseName=test
username=myuser
password=mypass
driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
classpath=C:\\Program Files\\Microsoft SQL Server 2005 JDBC Driver\\sqljdbc_1.2\\enu\\sqljdbc.jar
changeLogFile=database-changelog.xml

When using liquibase against an existing database you can run the following commands:

liquibase generateChangeLog
liquibase changelogSync

The first command will create an XML file called database-changelog.xml containing the extracted data model.
The second command is optional, but useful if you want to apply new changes to the current database. It marks the extracted changesets as already executed in the database.

Now that you have a starting point, you can proceed to add new changesets to the database-changelog.xml file. To apply these new changes just run the following command:

liquibase update

This is the same command that you use for brand new databases. During an update operation liquibase will compare the changesets in the XML file to the changesets already applied to the target database.

For more advanced usecases I suggest reading the liquibase documentation and the following answer may also help:

1
  • @ Mark O'Connor : tnx +1. I read this articles already. Is it possibe to run some command line for Liquidbase to deploy my database from create script or do I need to create Liquidbase project manually etc.? Can I just load Liquidbase schema from sql create database file and then deploy? I just need to deploy changes, do not need other stuff like version control. Just need to apply changes and keep the data.
    – rumburak
    Oct 5, 2012 at 20:23
0

To be able to generate Visual Studio Database Project from Entity Framework Model You need to install Entity Designer Database Generation Power Pack.

You need to add Database Project to Your solution and then create edmx model with the same name. Then right click on edmx workspace and select Generate Database from Model and from generation menu Sync Database Project.

You can then deploy this Sql project from Visual Studio to Sql Server.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.