为什么 entity framework 不向 .mdf 文件插入数据?

Why entity framework not inserting data to .mdf file?

我正在使用 控制台应用程序 将数据插入 App_Data 文件夹中的 .mdf 文件和项目文件夹中的 .edmx 文件。

以下相同的代码适用于 mvc 但不适用于控制台应用程序。

Table 是:

CREATE TABLE [dbo].[tbLegalDetails] (
[LegalStatusId]           INT            NOT NULL,
[LegalStatusName]         TEXT           NULL,
[LegalStatusHeading]      TEXT           NULL,
[PatentOfInvention]       NVARCHAR (100) NULL,
[EventCode]               VARCHAR (100)  NULL,
[EventExplination]        TEXT           NULL,
[CCOfCorrespondingPatent] NVARCHAR (100) NULL,
[CorrespondingPatentD]    INT            NULL,
PRIMARY KEY CLUSTERED ([LegalStatusId] ASC)
);

插入数据的代码是:

ConsoleApplication__DynamicWebBrowserDatabaseEntities db = new ConsoleApplication__DynamicWebBrowserDatabaseEntities();
List<tbLegalDetail> hLegalDetaili = db.tbLegalDetails.ToList();

[Here count is shown as 0]

tbLegalDetail tbLegalDetail = new tbLegalDetail();
tbLegalDetail.LegalStatusId = 3;
tbLegalDetail.LegalStatusName = "INPADOC legal";
tbLegalDetail.LegalStatusHeading = "COMPOSITIONS ANDAPY";
tbLegalDetail.PatentOfInvention = "2003287377";
tbLegalDetail.EventCode = "FGA";
tbLegalDetail.EventExplination = "LETTSTANDARD PATENT";
tbLegalDetail.CCOfCorrespondingPatent = "dfs";
tbLegalDetail.CorrespondingPatentD = 1212;
db.tbLegalDetails.Add(tbLegalDetail);
db.SaveChanges();
List<tbLegalDetail> hLegalDetail = db.tbLegalDetails.ToList();

[Here count is shown as 1]

Console.ReadLine();

但是当我查看 .mdf 文件时,我看不到添加的行。 当我再次 运行 时,我将显示计数为 0。

请帮忙。

控制台应用程序或windows表单应用程序使用调试文件夹中的资源(副本)。可以从调试文件夹中显示的 .mdf 文件中获得更改(就在 运行 之后/第二个 运行 之前)。

愿这篇文章能为您讲述更多.. http://www.codeproject.com/Articles/663453/Understanding-Clean-Build-and-Rebuild-in-Visual-St

我根据@sgmoore 和@vipin 给出的评论回答这个问题。

我更改了 |DataDirectory|在 App.config 文件中的连接字符串到完整路径 解决了问题

谢谢。