我正在使用C#创建一个SQLite表:
db2.CreateTable<Phrase>();
public class Phrase : IPhrase
{
public Phrase()
{
}
[PrimaryKey, NotNull]
public bool Favorite { get; set; }
public int CategoryId { get; set; }
public int Modified { get; set; }
public string English { get; set; }
public bool Hidden { get; set; }
}
有没有办法可以将Hidden的值赋予默认值0?
答案 0 :(得分:1)
尝试
public class Phrase : IPhrase
{
public Phrase()
{
}
[PrimaryKey, NotNull]
public bool Favorite { get; set; }
public int CategoryId { get; set; }
public int Modified { get; set; }
public string English { get; set; }
[NotNull, Default(value: 0)]
public bool Hidden { get; set; }
}
答案 1 :(得分:1)
如果未提供值,则默认情况下布尔字段为0(或false)。
此外,您似乎将布尔“最爱”设置为主键?您可能希望'categoryid'成为关键?