3

I'm wanting to create a database programmatically from the edmx or edmx.sqlce file in my project. I read the best practice when sending the data out to users this is the best way. But I haven't found anything on it. Or is it best to create it and send it out with the program? How would I do updates to the database if I did this? How do I tell which version the database is?

Sorry for the multiple questions in one. I'm new to programming/databases so I don't know how it is normally done and can't seem to find a book on it either.

1 Answer 1

3

The best practice in this scenario is creating installation package (.msi) which will install your application and execute script to deploy the database. The script can even check dependencies like SQL Server CE and .NET Framework. This will also solve your problem with database version because .msi installation package keeps this information so you can create upgrade .msi which will know that it must execute only change script for database instead of creating a new one. Be aware that creating installation packages is pretty complex task but this is the way how it is done in real products shipped to customers. In both my current and previous company we used WiX to create installation packages but we have special guy who does this.

There is no API to create database from EDMX file. Moreover EDMX file is not part of built application. Database generation is feature of VS2010 which uses either workflow or T4 template to transform EDMX into SQL script. The default template can create only full database script and you must execute it.

I described the way of creating deployment script for new version of database in separate question. It is related to code-first (EFv4.1) but the principle is the same. If you need to keep information about database version you can have special table for that and check the value in the table at the beginning of the upgrade script.

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

1 Comment

I have a schema diff tool for SQL Server Compact, if that helps

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.