SQLiteDb.db.InsertAsync always returns 1
Whenever I try to insert in a loop I always get 1. For example;
int g = await SQLiteDb.db.InsertAsync(market);
1 means success, ok.
How can I get the id of the created object? I think the documents state that it returns the id of the created object.
For me, the property decorated with [PrimaryKey] attribute (which is an int) gets set automatically by the Insert method. The return value represents either success or the number of affected records (not sure). We're normally not interested in this value at all :)
You can Read the docs https://github.com/praeclarum/sqlite-net
If you want to get the id(auto generated), then you can use
Stock stock = new Stock()
{
Symbol = "AAPL"
};
var conn = new SQLiteAsyncConnection(databasePath);
await conn.InsertAsync(stock);
Debug.WriteLine("New customer ID: {0}", stock.Id);
This is also in the docs. @praeclarum , our great man, wrote it very clear.
Insert actually returns the number of rows inserted.
As @hupo376787 said, the Id is stored in the designated PrimaryKey of the object you inserted.
Wow. Just wanted to stop by and say thanks for this! First time a piece of code makes me feel retarded and is also an eye opener. I've been doing all sort of gymnastics trying to get that ID when it was actually assigned to the object by default this whole time. 😄

Task
c'mon guys .. It could've said "Retreives" or "Returns the number of rows inserted"