這並不能解決您使用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,只是數據和是的 –