CRUD Entity Flowpath

Using the sample in Document I added some create code to the Row_Inserted server event for one of our tables to add a record to a child table. The add is successful, however the row_inserting server event of the child doesn't seem to fire/doesn't hit a breakpoint in Visual Studio (I'm using it to check for duplicate records).

I did have to change the function call to Insert instead of InsertAsync (since row_inserted isn't async) but I was still expecting the entity methods to fire. Is this limited to async only or did I miss something else?

var contactTable = (Contacts<Entities.Contact>)ResolveTable<Entities.Contact>();
string mySQL = "SELECT * FROM ExtraInfo WHERE Account = " + newRow["Account"];
List<Dictionary<string,object?>> rows = (List<Dictionary<string,object?>>)ExecuteRows(mySQL);
foreach (Dictionary<string,object?> row in rows)
{
    var contact = contactTable.Create();
    contact.CompanyId = ConvertToInt(newRow["MasterID"]);
    contact.RegularPhone = ConvertToString(row["RegularPhone"]);
    contact.RegularEmail = ConvertToString(row["RegularEmail"]);
    contact.CriticalPhone = ConvertToString(row["CriticalPhone"]);
    contact.CriticalEmail = ConvertToString(row["CriticalEmail"]);
    contactTable.Insert(contact);
}
  1. Row_Inserted event can be made async, see Async Server Events,
  2. When working with entities, only the entity events will be fired:

    Triggers entity events - Created, Loaded, Inserting, Inserted, InsertFailed, Updating, Updated, UpdateFailed, Deleting, Deleted, DeleteFailed events (table level).

You can add your event handler to the Inserted event handler of the table, e.g.

table.Inserted += (sender, e) => { ...Your handler code... };
  1. Thanks. I'm ok with leaving it sync.
  2. Is there a way to link the event handler to the existing (child) record_inserting function? My thought with processing this way was a) If a user adds a record to the child table via its page, the inserting event will fire, or b) if a user adds a parent record (which then auto adds a child record) the inserting event would also fire (keeping me from having to duplicate the code). I could run it as a global function (I think), I just wondered if the new entities could make it easier. (I'm still wrapping my head around the entities, not making direct SQL calls is a hard habit to break).

Just wanted to check in and see if anyone knew if the child entity methods (ex. inserted) should be triggered when Insert is called on the table.

You may try to trigger the Row_Inserted server event yourself, e.g. in the Table_Load server event for the child table:

Inserted += (sender, e) => RowInserted(e.Value);

Thanks, that worked. In case it helps anyone else:

Inserting += (sender, e) => RowInserting(null, e.Value);
Inserted += (sender, e) => RowInserted(null, e.Value);

One side note, the return from RowInserting is a bool indicating if the operation should be cancelled. This cancel code is only processed on the "add" page, so linking the event alone in table_load will not make use of the cancel logic. Ultimately, I created a global function to handle my need and didn't link the events.