3

My project:

  • I have a c# data project (currently in TFS, but it will be moved to git) with multiple branches.
  • Most branches have their own development database (on an azure SQL server)
  • I am using Entity Framework 6 (Database first with edmx Model, created in the EF4 days)
  • The database project is used by multiple solutions / starting projects (a hosting project as main project)

I want to automatically have the correct development DB in the EF "Update model from database" dialog. The connection string that should be used must be in the hosting project web.config (the app itself runs on azure, so the web.config connection string is never used during runtime)

Currently I have a process to:

  • Update the web.config (and all other configs) with a connection string to the specific branch database
  • I check that change into Source Control
  • I do a "discard merge" to the main branch (marking the changes as merged without changing the "main" database connection or other dev connections if merging that checkin to other branches)

This process is far from ideal.

I tested with external config files (using the "file" or "configSource" attributes) but that:

  • Cannot include a file in the parent directory (i would have to create a DatabaseConnection.config file for each project instead of only one central one)
  • still has the problem if either checking into SC (no real win) or a process to create the file (in the pre-build event). This would require a build before I can update the database (in a new branch / after switching branches when using git?)

So still not ideal.

I did not find anything about the database designer (update model wizard) able to read the connection from somewhere other than the start project config file (?)

I also know that many people have databases per developer and not per branch, but I need the branch databases in this case. I also only have problems with using the correct branch database when updating the model. The correct branch / development database is chosen automatically during runtime (naming convention)

-> Does anybody has any hints about using

  • Multiple .config files / projects
  • with one database per branch (mostly)
  • with often branch switches
  • or any way to tell the EF6 "Update model from database" wizard where / how to get the connection string from another source

Converting to "Model first" is also not really possible at the moment because of the size of the projects and deploy mechanics

Felix
  • 97
  • 4
  • I don't believe you can change the behaviour of this wizard in particular. I looked in the EDMX file but that also doesn't seem to show any hint. Have you tried a hacky way of using shortcuts or potentially even symbolic links to a connections.config in a parent directory? – Gigabyte Jan 13 '17 at 18:37
  • I don't understand why this is downvoted. The question shows ample research effort, it's clear, and it's useful to know if something *isn't* possible. (Which I'm afraid is true). – Gert Arnold Jan 14 '17 at 10:41
  • I was afraid of that answer @Gigabyte. :-) I might try something with symbolic links, thanks for the idea. But that still leaves me with the issue of _when_ I will create / update the config file. A pre-RunUpdateWizard event would be nice :-) – Felix Jan 16 '17 at 08:49
  • @GertArnold thanks, I've seen enough "what did you already try?" comments and did not want to be the guy asking something without research first. :-). – Felix Jan 16 '17 at 08:52
  • @Felix You're right, that doesn't solve it. Offhand, I'm thinking of two options here: (a/difficult) create a visual studio plug-in and see if there's an extensibility point similar to what you mentioned - or - (b/okay-ish) use a pre-build task in MSBuild that runs a script to modify the config files (back) to what you desire. In the workflow that *only* requires a rebuild. – Gigabyte Jan 16 '17 at 13:35
  • I will change it as soon as we switched to git. Git has a "post-checkout" hook that I can use to trigger the re-creation / update of the databaseconnection.config file (one for each startup project) with the correct database config for that branch - no rebuild required :-). Not an exact solution to my problem but close enough for my requirements – Felix Jan 23 '17 at 16:05

0 Answers0