这并不能解决您使用Linq的XML帮助程序的情况,但处理此问题的好方法是单独创建数据库(如在控制台应用程序项目中)并加载它与你需要的数据。接下来,将SDF文件作为内容复制到Windows Phone项目中。最后,在部署应用程序时,将数据库从部署位置复制到独立存储中。这样,你不必处理XML文件或类似的东西。从部署位置复制到隔离存储是一件简单的事情。我工作的一个(相当长)博客贴子,讨论所有关于这一点,但你需要的核心代码是这样的:
// Obtain the virtual store for the application.
IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication();
// Create a stream for the file in the installation folder.
using (Stream input = Application.GetResourceStream(new Uri("ReferenceDB.sdf", UriKind.Relative)).Stream)
{
// Create a stream for the new file in isolated storage.
using (IsolatedStorageFileStream output = iso.CreateFile("ApplicationDB.sdf"))
{
// Initialize the buffer.
byte[] readBuffer = new byte[4096];
int bytesRead = -1;
// Copy the file from the installation folder to isolated storage.
while ((bytesRead = input.Read(readBuffer, 0, readBuffer.Length)) > 0)
{
output.Write(readBuffer, 0, bytesRead);
}
}
}
然后你就可以连接到数据库正常和读/写数据成天:
var db = new MyDataContext("Data Source = 'isostore:/ApplicationDB.sdf';");
您可以在https://github.com/ChrisKoenig/ReferenceDatabase
克里斯从我的GitHub库下载一些示例代码
你能稍微更清晰这里.....它听起来像你tryi在下载应用程序之前将XML预安装到独立存储中......是吗? – Keeano
我不知道这可以更清楚吗? 我想在用户安装应用程序时准备好数据库 也许不会在下载之前预先安装xml,只是数据和是的 –