0

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;
            }
9
  • when you create a new instance of the class using the first method, is the value set to true? Commented Feb 6, 2020 at 1:25
  • Correct it is set to true for data in the database . But I can’t seem to add new data where it would be false . Commented Feb 6, 2020 at 1:26
  • so if you create a new instance, set it to false, and then insert it into the db, what specifically is happening? Commented Feb 6, 2020 at 1:32
  • I create the new instance set the default value to true using just the NotNull and equal true. Then start the process to update the data and the once it goes to update to false it errors Commented Feb 6, 2020 at 1:37
  • Something like 02-05 16:11:12.599 I/Choreographer( 8302): Skipped 1040 frames! The application may be doing too much work on its main thread. 02-05 16:11:12.658 D/Mono ( 8302): DllImport searching in: 'e_sqlite3' ('libe_sqlite3.so'). 02-05 16:11:12.658 D/Mono ( 8302): Searching for 'sqlite3_extended_errcode'. 02-05 16:11:13.116 D/Mono ( 8302): Commented Feb 6, 2020 at 1:38

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.