我测试了这个操作,我得到了以下结果。
首先,我的模型像下面的代码。
public class Prijem
{
[PrimaryKey, AutoIncrement, Unique]
public int BCode { get; set; }
public string Name { get; set; }
public string FirmName { get; set; }
public string ItemCode { get; set; }
public string Count { get; set; }
}
我使用以下代码插入数据。
await App.Pdatabase.SavePrijemAsync(new Prijem() {Name="New",FirmName="55Fame" ,ItemCode="dg",Count="15"});
我的SavePrijemAsync方法如下代码。
public Task<int> SavePrijemAsync(Prijem prijem)
{
if (IsExisted(prijem))
{
return _database.UpdateAsync(prijem);
}
else
{
return _database.InsertAsync(prijem);
}
}
我在 sqlite 数据库中得到了类似以下截图的记录。

然后我只添加一个名为MyImage
public class Prijem
{
[PrimaryKey, AutoIncrement, Unique]
public int BCode { get; set; }
public string Name { get; set; }
public string FirmName { get; set; }
public string ItemCode { get; set; }
public string Count { get; set; }
string image = " Image";
public string MyImage
{
set
{
if (image != value)
{
image = value;
}
}
get
{
return image;
}
}
}
我使用了如下代码的更新操作。
await App.Pdatabase.SavePrijemAsync(new Prijem() {Name="New",FirmName="55Fame" ,ItemCode="dg",Count="15" });
并像下面的代码那样插入操作。
await App.Pdatabase.SavePrijemAsync(new Prijem() { Name = "New11", FirmName = "55Fame", ItemCode = "dg", Count = "15" });
我在数据库中得到了结果,如下图所示。

最后,我们可以得到结果,如果我们给模型添加一个属性。此列将添加到 sqlite 数据库中,但默认值我们必须手动更新它的现有数据,如果我们将新值插入数据库,将添加默认值。