开发者

MDF database inside project. Visual Studio Server Explorer not showing changes to the data

I've added a new MDF file to a .NET4.0 class library project, created a single table and a LINQ to SQL data model in order to access it. The connection string that was automatically adde开发者_JAVA技巧d is:

Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ClosedIncidents.mdf;Integrated Security=True;User Instance=True

I run some code against it that first prints out the tables records to the console, add's a record, and then prints out all records again. The idea is to just check that after VS closes the MDF file retains the changes. This is proved true as on a second run of the app it moans that it can't add the same hard coded record because it already exists. The issue I am pondering on, is why when in Server Explorer if I view the data of the table that it shows nothing is there.

My understanding is that it attaches the server or user sql server instance directly to the mdf file within my project. Changes through the instance are written back to the source mdf, not a copy of it. Why then does the program show the record being added but not Server Explorer?


Chances are the file is being copied to the output directory, and so the IDE and the application are actually touching different files. You can confirm this by doing a clean build.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜