2016-11-28 30 views
1

我正在使用SQLite開發我的應用程序,在「調試」模式下工作完美。UWP - 在原生編譯時出現SQLite問題

當我嘗試「釋放」它(編譯「Native」)時,問題開始,看起來像UWP不支持Reflexion。

我目前使用該套餐:

SQLite.Core.UAP 
SQLite.Net-PCL 

例如,如果我嘗試這樣做:

private void CreateDatabase() 
    { 
     var dbPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "StoredEvents.sqlite"); 
     SQLiteConnection SQLiteConn = new SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), dbPath, false); 

     SQLiteConn.CreateTable<StoredEvents>();    
    } 

這些都是錯誤的:

ILTransform_0027: Method 'CreateLambda' within 'System.Linq.Expressions.Expression' could not be found. 


Error at SerializationAssemblyGenerator.Program.AddKnownContractsLists(McgCodeTypeDeclaration container, ContractTables tables) 


Severity Code Description Project File Line Suppression State 
Error  at SerializationAssemblyGenerator.Program.GenerateDataContractSerializerHelperCode(IEnumerable`1 contracts, IEnumerable`1 jsonContracts, IEnumerable`1 wcfSerializers) 



ILTransform_0000:  MCG : warning MCG0006: Unresolved P/Invoke method '_TPM_Init!tpm.dll' in assembly 'TSS.UWP, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' because it is not available in UWP applications. Please either use an another API , or use [DllImport(ExactSpelling=true) 

我應該如何重構代碼?

我應該使用不同的庫嗎?

回答

0

當我從Silverlight更新我的應用程序到UWP時,我遇到了同樣的問題。我在某處讀過一篇文章(試圖找到它,但無法做到),其中說用於UWP的SQLlite可用於Windows 10部署。

enter image description here

上面是VS擴展。你可以從工具 - >>擴展&更新

下面是我的參考看起來像。

enter image description here

而且我注意到,您不關閉您的數據庫連接。最好在using聲明中使用它。您的CreateTables()將如下所示。

private void CreateDatabase() 
{ 
    var dbPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "StoredEvents.sqlite"); 
    using (SQLiteConnection SQLiteConn = new SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), dbPath, false)) 
    { 
     SQLiteConn.CreateTable<StoredEvents>(); 
    }  
}