0

Here is my code first:

 DbHw10Ent de = new DbHw10Ent();

        Sales1 sal = new Sales1();

        sal.SalesAmount = 6900;
        sal.SalesDate = DateTime.Now;
        sal.TaxAmount = 100.00M;

        de.Sales1.Add(sal);
        de.SaveChanges();


        var sales = de.Sales1;

        foreach (var o in sales)
        {
            Console.WriteLine("{0}--{1}--{2}--{3}", o.SalesID, o.SalesDate.ToShortDateString(), o.SalesAmount, o.TaxAmount);
        }

        Console.ReadLine();

Take note that it displays in the console but when I try to refresh my tables in the object explorer, nothing changes and when I close my solution, everything resets back to normal. Am I missing something here? this is my solution explorer

NOTE: It seems that The updated database stays in the DEBUG folder in the bin/. What will I do to be able to update the database in the databse explorer as well!

SharpGobi
  • 144
  • 1
  • 13
ejmtv
  • 198
  • 5
  • 18
  • Where is your database located, what kind of database is it. Maybe you have a local db file which is copied to `Debug` and `Release` folder. – grek40 Jun 09 '17 at 11:08
  • it is a Service-based db – ejmtv Jun 09 '17 at 11:17
  • Looks file-based to me according to the picture... is there any build action associated with the DbHw10.mdf file? – grek40 Jun 09 '17 at 11:18
  • right click on the database file (DbHw10.mdf ) and select "copy if newer" for reference (https://msdn.microsoft.com/en-us/library/ms246989.aspx) – Ihtsham Minhas Jun 09 '17 at 11:19
  • dorry idk what is that – ejmtv Jun 09 '17 at 11:20
  • 1
    Possibly related: https://stackoverflow.com/questions/17444044/data-lost-from-mdf-file-as-i-exit-application or even better https://stackoverflow.com/questions/17147249/why-saving-changes-to-a-database-fails – grek40 Jun 09 '17 at 11:21
  • Possible duplicate of [Why saving changes to a database fails?](https://stackoverflow.com/questions/17147249/why-saving-changes-to-a-database-fails) – grek40 Jun 09 '17 at 11:24
  • i did that........ – ejmtv Jun 09 '17 at 11:24
  • 1
    What does it mean "everything resets back to normal?" Does it clear the database? Does it insert the missing record in the database? Does it recreates the database? – Chetan Jun 09 '17 at 11:25
  • it does not show the record of what I have inserted programatically – ejmtv Jun 09 '17 at 11:28
  • Are connecting to the correct database in the code and looking at the same to verify the result? Can you,share the connection string used by the linq? – Chetan Jun 11 '17 at 02:30

0 Answers0