3

I am working with ASP.NET C# MVC 5.

.mdf/.ldf files in App_Data do not appear on Pending Changes in team explorer. Therefore I can't check them into TFS(visual studio online). I've tried recreating the project a few times and none worked. What might be the cause for this?

awonderer
  • 665
  • 9
  • 26
  • 2
    It seems like a bad idea to put them into version control anyway. I'm not sure what the specific problem is (perhaps they're ignored by default), but you should consider not putting them in. – siride Aug 05 '14 at 00:49
  • Thanks for your comment. Why do you say it's a bad idea? How do you find out what are ignored? – awonderer Aug 05 '14 at 02:20
  • 1
    source control systems are not well-designed to include binary files such as databases. More importantly, an actual database is not code or source; it is actual data and the product of software. Just as you do not store your binary files in source control, you don't store databases. You store instead scripts and code to update and maintain the database. Also, how can you ever use the database to store real data from an application if it could be replaced from source control on release? It must be independent of source control. – siride Aug 05 '14 at 03:16

2 Answers2

5

Go to Team Explorer and locate Excluded Changes and you should find it excluded. Right click the App_Data folder and include it.

But you might want to reconsider including the database files. As you're developing and testing, every little database interaction will trigger a change and most of those are trivial. Also, if someone else is working on this project, they may not want your database file to overwrite theirs when they Get Latest Version.

If you're using Entity Framework Code-First, the database is automatically generated when you build the project I believe, otherwise you just run the Update-Database command to do it. This lets everyone collaborating have their own local database file to work with. You can also utilize migrations to make updates to the database structure. If you want the database to be generated with pre-populated data, you should utilize the Seed method.

Tyler Morrow
  • 949
  • 8
  • 31
  • Thanks for the excellent answer, including why not to include the `App_Data` folder when doing EF Code-First development. – Shiva Nov 18 '16 at 00:51
  • 1
    No problem. Just to be clear, I'm of the opinion you should not include the App_Data folder in general - see second paragraph. Good luck! – Tyler Morrow Nov 21 '16 at 15:04
0

This is a general question. As already answered by 'Ty Morrow' in above comment there is an initial Seed Method in Entity Framework which ensures that all values are inserted. However there are many scenarios that you also need to work with the latest added / removed DB entries not present in the seed method.

Please perform the following steps to ensure that your data directory file is included in the source control.

  • Click App_Data folder and on encircled toolbar click on Show All Files as shown below in the snapshot

See the Encircled and click on **Show All Files**

  • Right Click on your MDF (Data Source) File and click on Include in Project
  • Right Click again on your MDF File and click on Include in Source Control
  • Simply Check in the file by Right Clicking on root project folder link and file show be now part of Source Control
vibs2006
  • 6,028
  • 3
  • 40
  • 40