Merging TFS Branches with an EF Object Present

Visual Studio 2012 added integrated support for EDMX files. Being able to open and update the model from within the IDE allows for quick updates to the schema without using an external program or command line argument.

Adding EDMX files to source control is one of the largest pains a developer will ever face while merging a branch. When the design tool updates the schema in a EDMX file, it does so by completely wiping away the previous files (an EDMX is comprised of a *.cs file for each table in the database) and then recreating them with the updated schema. This present a large problem to TFS when you try and merge two branches that contain the same EDMX. TFS sees two separate files in both of the branches since it was deleted and then recreated. This blocks the ability to merge the changes because the manager will not allow merging changes between what it sees as “different” files.

After searching I came across this Stack Overflow thread with other developers in similar predicaments.

The simple solution I’ve found is to have only one developer update EDMX files when needed, and when merging to ignore the entire file from the merge. After the merge is complete go back into the solution and update the model from whichever database it needs to be pointed at.

The client I am currently working with requires the Cisco AnyConnect VPN solution to connect to their internal network for development. Their IIS and db servers require this due to being behind their firewall. Once connected with the Cisco client VS loses its ability to talk to the TFS. The solution must be taken offline by closing and opening the solution (or by using the “TFS Go-Offline” plugin). If you’re updating the EDMX offline I’ve found the most successful way is to select all the items in the designer, delete them, then save the EDMX, then update model from DB. Attempting to update the model without deleting them fails because the IDE needs to ask you if you’d like to overwrite the write-protected file (because you’re away from TFS the files can’t be checked out on the fly). If you update without deleting the update will fail silently, leaving you puzzled as to why you’re Intellisense is failing to pick up your new objects.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.