I have a Messages table with column identifiers (primary key, auto-increment) and Content (text).
I have a Users table with column names (primary key, text) and Hash.
A message is sent by one sender (user) to many recipients (user), and the recipient (user) can have many messages.
I created a Messages_Recipients table with two columns: MessageID (referring to the column identifier of the message table and the recipient (referring to the username column in the "Users" table). This table represents many, many relationships between recipients and messages.
So, I have a question. The identifier of the new message will be created after it is stored in the database. But how can I use the MessageRow link I just added to get this new MessageID?
I can always find the database for the last row added, but is it possible that it can return another row in a multi-threaded environment?
EDIT: as I understand it, for SQLite you can use SELECT last_insert_rowid (). But how can I call this statement from ADO.Net?
My Persistence code (Messages and Recipients are DataTables):
public void Persist(Message message) { pm_databaseDataSet.MessagesRow messagerow; messagerow=messages.AddMessagesRow(message.Sender, message.TimeSent.ToFileTime(), message.Content, message.TimeCreated.ToFileTime()); UpdateMessages(); var x = messagerow;
database sqlite primary-key auto-increment junction-table
Dabblernl Jan 24 2018-10-24T00: 00Z
source share