[英]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. 我已经向.NET4.0类库项目中添加了一个新的MDF文件,创建了一个表和一个LINQ to SQL数据模型以便对其进行访问。 The connection string that was automatically added is: 自动添加的连接字符串为:
Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\ClosedIncidents.mdf;Integrated Security=True;User Instance=True 数据源=。\\ SQLEXPRESS; AttachDbFilename = | DataDirectory | \\ ClosedIncidents.mdf;集成安全性= True;用户实例= 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. 想法是仅检查VS关闭后MDF文件是否保留更改。 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. 我的理解是,它将服务器或用户sql服务器实例直接附加到项目中的mdf文件中。 Changes through the instance are written back to the source mdf, not a copy of it. 通过实例所做的更改将写回到源mdf,而不是其副本。 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. 可能会将文件复制到输出目录,因此IDE和应用程序实际上正在接触其他文件。 You can confirm this by doing a clean build. 您可以通过全新构建来确认。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.