I am using sqlite-net-pcl and adding a new column to a database DTO and I wanted to set the default value to true and then once I have update the data it would update to the correct value. But the default is not working for me in xamarin.
is there any other way to do this?
[NotNull]
public boolean Istaxable { get; set; } = true;
This will block me from doing a update.
[NotNull, Default(value: true)]
Error default is unknown
DTO
public class DtoTaxableLink
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
[NotNull]
public bool IsTaxable { get; set; } = true;
}
service
await App.LocalDB.InsertTaxableLinksAsync(BuildDbTaxableLinkItem( public Task<int> InsertTaxableLinksAsync(List<DtoTaxableLink> taxableLinks)
ListResponse.Data));
local db
public Task<int> InsertTaxableLinksAsync(List<DtoTaxableLink> taxableLinks)
{
return database.InsertAllAsync(taxableLinks, true);
}
Helper
private static List<DtoTaxableLink> BuildDbTaxableLinkItem(List<TaxablelineLink> taxableLinks)
{
List<DtoTaxableLink> dtoTaxableLink= new List<DtoTaxableLink>();
foreach (var taxink in taxableLinks)
{
DtoTaxableLink dtoTaxableLink= new DtoTaxableLink();
dtoTaxableLink.IsTaxable = taxableLinks.IsTaxable ;
dtoTaxableLink.Add(dtoTaxableLink);
}
return dtoTaxableLink;
}
According to your description, you want to set the default value to true when using sqlite-net-pcl and adding a new column to a database.
You can do it through property itself, field default value not going change until another value going to set.Please take a look the following code:
public class User
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public string userName { get; set; }
public string password { get; set; }
private bool _sel = true;
[NotNull]
public bool Selected
{
get { return _sel; }
set { _sel = value; }
}
}
Now you can see I set Selected property default value is True, then you can update this value that you want.