Where is the data stored?

Mar 1, 2011 at 1:35 PM

I have created the EF scaffolding in my project. I have an SQL Server 2008 database attached to it via a connection string in the Web.config. I do not have an App_Data folder in the project. I have run the the web site and created a record in my scaffolded table. I expected to see a new table added to the SQL Server database, but no, there is no table. Neither has an App_Data folder been created. Yet I can close the web site and re-open it and the record is still there.

So, where is the table containing the data being stored?

Mar 2, 2011 at 5:14 AM

Did you check the SQLEXPRESS Instance? Is it possible that the data is still stored there?

Mar 2, 2011 at 8:07 AM

That's why I'm asking the question. My SQL Server 2008 database has the following connection string declared

		<add name="RLSBCWebSiteDb"
			connectionString="data source=MAINPC\SQLEXPRESS;Initial Catalog=RLSBCWebSite;Integrated Security=True"
			providerName="System.Data.SqlClient" />

This database is already storing the tables for Roles and Membership which were generated by aspnet_regsql.exe and I expected the table generated by MvcScaffolding to be in there as well. But it's not. At least, I can't see it when I look at the list of tables through Server Explorer. It is not in any of the other three databases to which I have connections either. So where is it?

Mar 2, 2011 at 12:41 PM

I've found the database where the table has been stored. So now the question is: What do I need to add to the Scaffold EF generated code to make it use the above connection string? I assume something needs adding to the generated ...Context.cs file, but what?

Apr 10, 2011 at 5:43 PM

My question as well xiecsuk.  It seems to magically put it in SQLExpress.  I cannot find a reference to the connection string it uses anywhere.  Plus it calls my database some very long string.  How do you change this?

Apr 12, 2011 at 8:43 PM

magically = conventions

This blog explains the conventions in EF and how to manipulate them to use the connection string you desire.


Apr 13, 2011 at 8:15 AM

It would appear that EF Scaffolding has been replaced/renamed by EF Code First. There are a nunber of blogs from ScottG's blog site and the ADO.NET Team Blog that explain it fully. I have used this in my website and it weeks a treat.

Apr 13, 2011 at 11:53 AM

@ssuing:  Thanks for the link and the explanation.  @xiecsuk:  I suppose Code First could be considered scaffolding just for the EF piece.  I wonder how they might incorporate that into this scaffolding framework.

Jun 4, 2014 at 10:45 AM
Edited Jun 4, 2014 at 10:46 AM
Add a constructor to your generated DbContext class
    public class RLSBCWebSiteContext : DbContext
        public RLSBCWebSiteContext()
            this.Database.Connection.ConnectionString = WebConfigurationManager.ConnectionStrings["RLSBCWebSite"].ConnectionString;
Add to web.config
    <add name="RLSBCWebSite" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=RLSBCWebSite.Models.RLSBCWebSiteContext;Integrated Security=True;" providerName="System.Data.SqlClient" />