Search code examples
asp.net-mvcedmxaspnetdb

edmx populating mdf?


when i 'generate database from model' in an edmx file it asks for a datasource and generates a sql file and adds the data source to the app.config

if i choose sqlserver as the source it works fine and i can either use an existing database or create a new one and the tables get populated to it and its ready to use

possible to make that sql populate a new mdf file somehow?

-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 08/25/2010 10:41:33
-- Generated from EDMX file: c:\test\test.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [test];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

...

works fine against sqlserver but complains database not found when i connect to sqlexpress and to to populate a local mdf file in the project dir?

i have to make it use the connection string from the app.config somehow? or create the database in sql manager first? or modify the generated sql somehow (with the path of my created mdf maybe)?

thanks a lot


Solution

  • I tried running a query like this by right clicking on the local .mdf in the solution and choosing "New Query". I had to remove the "use [test]" and all the "GO"'s in the query text and it generated my tables correctly.