My Website has two databases, one for user accounts and one for content. Both are created code first, and both have data in them. But I have only one mdf file in the project. The site works locally, the content gets displayed, I can edit and add to it, and the changes are effective. I can add users, and their accounts work. But the only mdf file I have in the project is the user database.
I can connect to localdb in sql server managment studio and get only the user database. There's no database whose structure and tables would match the content database. I can go to server explorer in Visual Studio, and only the user database shows up under connections. I did of course refresh my solution explorer several times with "show all files" on. I even did a full disk search for all mdf files anywhere on my computer, and it didn't come up with one that would fit the bill.
I tried to fiddle with connection strings in web.config (of which there were none auto-generated) because I read that this could trigger the creation of the mdf file (although the context was always an empty database that didn't get created), but all that brought me was that the application now didn't find the database anymore either. reverting the changes in web.config did not resolve that issue, but reverting the whole project from svn did.
The database was migrated 10 times during development, always without error. Everything works fine, except I can't find the physical database anywhere. Which of course is a problem for deployment. I had noticed that I had only one mdf file in the project during development, but I didn't think much about it at the time. after all, everything worked (and still does).
Are there other means than mdf by which ASP.NET MVC can store a database? That data I'm seeing on the screen has to come from somewhere... but for all I can tell, not from an mdf file.
EDIT: after reverting and rebuilding, there was now a default connection string generated in web.config. However, it simply points to the user database, i.e. the file I can find in the App-Data folder:
connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-RAOC-20150430022043.mdf;Initial Catalog=aspnet-RAOC-20150430022043;Integrated Security=True" providerName="System.Data.SqlClient"
-----some more info-----
I have experimented with connection strings some more. On adding the following connection string to web.config, the .mdf file finally got created:
<add name="RAOCentities" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\raoc.mdf;Initial Catalog=aspnet-raoc;Integrated Security=True" providerName="System.Data.SqlClient" />
However, as was kind of expected, it didn't contain the content, so I got a null reference exception. Removing the connection string from web.config restored the old functionality. So the real question it comes down to is: Where is that content stored? and how can I put it into an mdf?
-----still more info-------
After some experiments, the conclusion that the content data is indeed stored inside the user database seems inevitable. At least that seems to be the only file that changes if I change the content according to an svn dif. But I can't see the tables in sql server managment studio. I can only see the tables from the user database (your default applicationdbcontext), not from my own entities. Yet everything points to the fact that the data is in there somewhere. Anybody got any ideas how that is possible?