Nithin B Nithin B - 5 months ago 45
C# Question

Why entity framework not inserting data to .mdf file?

I am using console application to insert data into .mdf file which is in App_Data folder and .edmx file in project folder.

The same below code is working with mvc but not console application.

Table is:

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,

Code to insert data is:

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;
List<tbLegalDetail> hLegalDetail = db.tbLegalDetails.ToList();

[Here count is shown as 1]


but when I look into the .mdf file I cant see the added row.
When I run again I will show count as 0.

Please help.


I am answering this question form the comments given by @sgmoore and @vipin.

I changed the |DataDirectory| in the connection string in App.config file to full path which solved the problem

Thank you.