edmx填充mdf?

发布于 2024-09-12 22:29:58 字数 800 浏览 5 评论 0原文

当我在 edmx 文件中“从模型生成数据库”时,它会要求提供数据源并生成 sql 文件,并将数据源添加到 app.config

如果我选择 sqlserver 作为源,它工作正常,我可以使用现有数据库或者创建一个新的表,然后将表填充到其中,并准备好使用

该sql以某种方式填充新的mdf文件?

-- --------------------------------------------------
-- 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

...

在 sqlserver 上工作正常,但当我连接到 sqlexpress 并在项目目录中填充本地 mdf 文件时抱怨找不到数据库?

我必须让它使用 app.config 中的连接字符串?或者先在sql管理器中创建数据库?或者以某种方式修改生成的sql(可能是我创建的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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如歌彻婉言 2024-09-19 22:29:58

我尝试通过右键单击解决方案中的本地 .mdf 并选择“新查询”来运行这样的查询。我必须删除查询文本中的“use [test]”和所有“GO”,它正确生成了我的表。

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.

风为裳 2024-09-19 22:29:58

我必须打开本地数据库实例,将查询复制到该窗口,单击“新建查询”,然后在那里执行它。有趣的是,生成的 SQL 允许您右键单击,但如果您随后选择“执行”,它就看不到意识到项目中有一个附加的 MDF....

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....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文