title: WP8/C#/SQLite: get last inserted id?
body: <p>SQLite with WP8 is driving me nuts. :(</p>
  
  <p>All I want to do is to retrieve the value of the last inserted id...</p>
  
  <p>I've got:</p>
  
  <pre><code>class ShoppingItem
  {
    [SQLite.PrimaryKey, SQLite.AutoIncrement]
    public int Id {get; set;}
    public string Name {get; set;}
    public string Shop {get; set;}
    public bool isActive {get; set;}
  }
  </code></pre>
  
  <p>Well, neither the used <code>SQLiteConnection</code> object nor its <code>Table&lt;ShoppingItem&gt;</code> seem to contain an appropriate member that contains the last ID.</p>
  
  <p>So I tried to do:</p>
  
  <pre><code>private int GetLastInsertedRowID()
  {
    int Result = -1;
    using (var db = new SQLiteConnection(m_DatabasePath)) {
      Result = db.ExecuteScalar&lt;int&gt;("SELECT last_insert_rowid();");
    }
    return Result;
  }
  </code></pre>
  
  <p>But this function always returns <code>0</code>.  :(
  But when I read all entries of <code>ShoppingItem</code>, their IDs have values != 0.</p>
  
  <p>So my question is: How can I retreive the last inserted id?</p>
  
  <p>PS: Changing the SQL query to <code>SELECT last_insert_rowid() FROM ShoppingItem;</code> gave the same result.</p>
  
  <p>PPS: Solutions like <a href="https://stackoverflow.com/questions/4341178/getting-the-last-insert-id-with-sqlite-net-in-c-sharp">Getting the Last Insert ID with SQLite.NET in C#</a> do not compile, apparently there is an older version SQLite used, with a totally different API</p>