I have a model class shown below.
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; }
}
When i try to update I get the error message as Cannot update Section: it has no PK
Below is my update Code
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;
}
The exception is thrown in SQLite.cs file with the error.
i hope a slight modification in code can fix the issue
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;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.