2015-12-09 34 views
1

我有一個如下所示的模型類。無法更新模型:它在Windows Phone 8.1中沒有PK c#

public class Section 
{ 
    [PrimaryKey] 
    public int section_id { get; set; } 
    public string name { get; set; } 
    public string url { get; set; } 
    public System.DateTime syncTime { get; set; } 
} 

當我嘗試更新我得到的錯誤消息無法更新章節:它沒有PK

下面是我的更新代碼

async public Task<bool> UpdateSection_SyncTime(int section_Id) 
{ 
    try 
    { 
     var sections = await db.Table<Section>().ToListAsync(); 

     foreach (var section in sections) 
     { 
      if(section.section_id == section_Id) 
      { 
       section.syncTime = DateTime.Now; // Update the Section Sync Time 

       if (await db.UpdateAsync(section) >= 1) 
        return true; 
      } 
     } 
    } 
    catch { } 
    return false; 
} 

異常在SQLite.cs拋出文件與錯誤。

回答

0

我希望在代碼中稍微修改就解決這個問題

foreach (var section in sections) 
     { 
      if(section.section_id == section_Id) 
      { 

       section.syncTime = DateTime.Now; // Update the Section Sync Time 
       App.DBConnection.Update(section); //update the db 

       if (await db.UpdateAsync(section) >= 1) 
        return true; 
      } 
     } 
+0

我應該使用非異步方法,而且我需要打開和關閉我的意思是首選的方法應該使用的連接。 – Sharath

+0

我試過使用SQLiteConnection sqlConn = new SQLiteConnection(App.DBPath); sqlConn.Update(部);但仍然是同樣的問題。 – Sharath

+0

有人可以幫我解決這個問題... – Sharath

相關問題