none
Delete does not persist in the database RRS feed

  • Question

  • Hello,

    I'm trying to implement the "Delete" operation in my ConsoleApplication program. I used a .sdf database and ADO.NET Entity Framework.

    I wrote these lines of code:

    I run the program and it delete first record. When I re-run the program, the record with Id=1 does not exist.Everything is good so far.

    But, if I look in the database, the record with Id=1 is still there. And now, if i re-run the program, this record appear again.

    What's wrong with the program? What I have to do to this program to work?

    I also tried to make a program that implemet the "Delete" , "Modify" and "Add" operations in WPF and WF and I had the same problem. I mention that in ASP.NET MVC 2 these lines of code works.




    Saturday, August 25, 2012 11:00 AM

Answers

  • Hi,

    Do you check the right sdf file ? Sometimes the issue is that the sdf file is part of the solution copied as part of the build to the output directory and this is the one that is used. So sometimes one reports that :
    - the apps seems to work fine because the app is correct, and the update is still seen during the same application run so all works as expected
    - the data seems to miss outside of the app (because the sdf file that is part of the solution rather than the one that is in the output directory is checked)
    - it seems incorrect on the next run (because the sdf properties for this file asked to "always overwrite" the sdf file so the file found in the output directory is overwritten with the one that is part of the solution)


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".

    Saturday, August 25, 2012 12:21 PM

All replies

  • Hi,

    Do you check the right sdf file ? Sometimes the issue is that the sdf file is part of the solution copied as part of the build to the output directory and this is the one that is used. So sometimes one reports that :
    - the apps seems to work fine because the app is correct, and the update is still seen during the same application run so all works as expected
    - the data seems to miss outside of the app (because the sdf file that is part of the solution rather than the one that is in the output directory is checked)
    - it seems incorrect on the next run (because the sdf properties for this file asked to "always overwrite" the sdf file so the file found in the output directory is overwritten with the one that is part of the solution)


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".

    Saturday, August 25, 2012 12:21 PM
  • Hi Deaconu;

    I believe that the post of Patrice is correct and here is Microsoft documentation on the issue.

    How to: Manage Local Data Files in Your Project

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Saturday, August 25, 2012 4:32 PM
  • Hi,

    Thank you for your help. I saw the database copy in "bin" folder, but I didn't modify the "Copy to Output Directory" option. Now I modify it and all goes well.


    Sunday, August 26, 2012 8:12 AM