Q:

Why InsertAll in SQLITE crashes?

I am using InsertAll to save an ObservableCollection TickRecords into SQLITE database:
private static readonly ObservableCollection<TickRecord> TickRecords = new ObservableCollection<TickRecord>();

TickRecord is define like this:`
public class TickRecord : INotifyPropertyChanged
{
//
// Primary Key
//
private long _key;
[PrimaryKey]
public long Key
    {
    get
        {
        return _key;
        }
    set
        {
        _key = value;
        OnPropertyChanged( "Key" );
        }
    }

//
// Timestamp
//
private DateTime _tickStartDate;
public DateTime TickStartDate
    {
    get
        {
        return _tickStartDate;
        }
    set
        {
        _tickStartDate = value;
        OnPropertyChanged( "TickStartDate" );
        }
    }

private DateTime _tickEndDate;
public DateTime TickEndDate
    {
    get
        {
        return _tickEndDate;
        }
    set
        {
        _tickEndDate = value;
        OnPropertyChanged( "TickEndDate" );
        }
    }

//
// Record Duration in Seconds
//
private byte _durationInSeconds;
public byte DurationInSeconds
    {
    get
        {
        return _durationInSeconds;
        }
    set
        {
        _durationInSeconds = value;
        OnPropertyChanged( "DurationInSeconds" );
        }
    }

and saving into SQLITE is done like this:
    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync( CoreDispatcherPriority.High, () => Database.Database.AddAllTickRecords( TickRecords ) );

and AddAllTickRecords is defined like this:
    public static void AddAllTickRecords( IEnumerable<TickRecord> list )
    {
    using ( var db = new SQLiteConnection( new SQLitePlatformWinRT(), DbPath ) )
        {
        db.InsertAll( list );
        }
    }

Any idea why I am getting an error here?
The error I getting from the debugger is:
    **An exception of type 'SQLite.Net.SQLiteException' occurred in SQLite.Net.dll but was not handled in user code
Additional information: Constraint**

and 

    **{SQLite.Net.SQLiteException: Constraint
   at SQLite.Net.PreparedSqlLiteInsertCommand.ExecuteNonQuery(Object[] source)
   at SQLite.Net.SQLiteConnection.Insert(Object obj, String extra, Type objType)
   at SQLite.Net.SQLiteConnection.Insert(Object obj)
   at SQLite.Net.SQLiteConnection.<>c__DisplayClass100_0.<InsertAll>b__0()
   at SQLite.Net.SQLiteConnection.RunInTransaction(Action action)
   at SQLite.Net.SQLiteConnection.InsertAll(IEnumerable objects, Boolean runInTransaction)
   at BTLE.Database.Database.AddAllTickRecords(IEnumerable`1 list)
   at BTLE.MainPage.<>c.<DecodeMessageResponse>b__123_0()}**

A:

Based on the error you are getting (SQLite.Net.SQLiteException: Constraint), the problem is not related to your code, but to the data you're trying to insert. You seem to be violating a constraint defined for the table in the database (e.g. a unique constraint for one of the fields, or a nullable constraint).
To find the cause, first check the constraints in the database, to see what kind of a constraint you could be dealing with. Then check the contents of the list before calling InsertAll. If you still can't identify what is causing the issue, you could try bisecting your list and saving only a part of it to identify the offending record first.

