title: EF4 Generate Database
body: <p>I am trying my hardest to find the simplest way to create a basic "model first" entity framework example. However I am struggling with the actually generation of the database, particularly the running of the SQL against the database.</p>
  
  <h3>Tools</h3>
  
  <ul>
  <li>Visual Studio 2010</li>
  <li>SQL Server 2008 Express</li>
  </ul>
  
  <h3>Process</h3>
  
  <ol>
  <li>Create a new class project</li>
  <li>Add a new Server-Database item (mdf) named "Database1.mdf" to the project</li>
  <li>Add an empty ADO.net Entity Model</li>
  <li>Create a simple entity (Person: Id, Name)</li>
  <li>Generate the Script selecting the Database1 connection created for me by visual studio</li>
  <li>Right click the script editor and select the "Execute SQL..." option</li>
  <li>Log in to SQLEXPRESS </li>
  </ol>
  
  <p>This is where is falls over saying it cant find a database name "Database1".</p>
  
  <p>The "problem" is that the SQL server has not had Database1 attached to it. I am 100% positive that Visual Studio use to attach a database to SQLExpress when it created a new database (Step 2). This appears to not be the case any more (even the beta of VS2010 did it). Can someone confirm this? or tell me how to get this to happen?</p>
  
  <p>Is there a way that I can modify the TSQL script to use an un-attached database. ie a file.</p>
  
  <p>I know I can use SQL Management Studio or sqlcmd to attach the database, but I would ideally like to avoid the solutions as I would like to see the cleanest method of just using visual studio. </p>
  
  <h3>Ideal Solutions (in order of most prefered)</h3>
  
  <ol>
  <li>Get visual studio to attach the newly created database</li>
  <li>Modify the generated SQL to point to file</li>
  </ol>
  
  <p>Thanks in advance.</p>