Entity Framework won't persist data in SQL Express (MDF)

后端 未结 4 1183
醉酒成梦
醉酒成梦 2021-01-02 03:20

I was developing an application using Entity Framework and storing data in a .mdf database. My code can read the data, apparently it can save too, but only apparently. It ge

4条回答
  •  没有蜡笔的小新
    2021-01-02 03:31

    I just found what was going wrong, and I guess there's nothing wrong actually. I forced an error, and then I could see the database that I was accessing was in the bin directory, the Visual Studio copied my database to the bin directory everytime I run the app, so that's why if I add some data manually I could see it, but the saves in the runtime aren't persisted. I always worked with database in servers, it's my first time with local databases, so I messed up it, but thankz a lot for the help!


    Edit: Providing a Solution

    If you wish to disable copying the database on build, then you have to acces the Copy to Output Directoy from the .mdf file from your Solution Explorer.
    Simply change it to Copy if newer or Do not copy.

    Be aware that Copy if newer holds some risks when accesing a .mdf Database.

提交回复
热议问题