edmx populating mdf?

半城伤御伤魂 提交于 2019-12-10 21:02:23

问题


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


回答1:


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.




回答2:


I had to open the local db instance, copy the query to that window, click New Query and then execute it there. Funny thing is that the generated SQL allows you to right click but if you then choose Execute it just can't see to realize there is an attached MDF to the project....



来源:https://stackoverflow.com/questions/3402260/edmx-populating-mdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!