mac*_*Jun 11 c# xamarin sqlite.net
我知道这是一个愚蠢的问题,但我无法在任何地方找到答案.如何在sqlite.net模型中为列设置默认值?这是我的模型类:
public class ItemTaxes
{
[PrimaryKey]
public string Sku { get; set;}
public bool IsTaxable { get; set;}// How to set IsTaxable's default value to true?
public decimal PriceTaxExclusive { get; set;}
}
Run Code Online (Sandbox Code Playgroud)
我想将Not Null列IsTaxable的默认值设置为true,我该如何实现?顺便说一句我不想使用原始的sql语句,即conn.execute();
谢谢.
Gab*_*nha 10
有点晚了,但对于那些来这里寻找答案的人:
public class ItemTaxes
{
[NotNull, Default(value: true)]
public bool IsTaxable { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
如果默认属性在您使用的 SQLite-net 版本中不可用,您可以像往常一样使用自动属性来分配默认值。
public class ItemTaxes
{
public bool IsTaxable { get; set; } = true;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4268 次 |
| 最近记录: |