Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

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:

SQL
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)
);


Code to insert data is:


C#
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();


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.

What I have tried:

I tried to change the locations of the mdf and .edmx files from project folder to App_Data (both in same, one in each)
But did not work for me
When I try to create .edmx file it says "The connection you selected uses a local data file that is not in the current project.Do you want to copy it to project." which I don't get in MVC though .mdf file is in App_Data folder.
.
Posted
Updated 28-Oct-16 1:51am
v2
Comments
Richard Deeming 28-Oct-16 11:33am    
It sounds like you're overwriting or re-creating the database each time you run the application.

Have you got an empty copy of the mdf file somewhere in your project, with the "Copy to output directory" set?
BacchusBeale 29-Oct-16 1:23am    
Why aren't you using SQL Server Management Studio or SQLConnection string?
johannesnestler 2-Nov-16 10:02am    
get the return value from Save call and see if you get the expected '1' (that you list has now one element was done by add call, has nothing todo with save - so check this first.) After that I'd say what Richard meant sounds reasonalbe (you overwrite it somehow - so check your surrounding Code)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900