PostCreate can't see the data just inserted

PostCreate can't see the data just inserted

shuminliushuminliu Posts: 10Questions: 4Answers: 0
edited March 2021 in Editor

I set a function for postCreate, when the function is called, it seems the db operation is not finished:

public ActionResult ProcesstUsers()
            var request = HttpContext.Request;
            var DbType = "sqlserver";
            var dbConnection = "......";

            using (var db = new Database(DbType, DbConnection))
                var editor = new Editor(db, "User")
                    .Field(new Field("User.Username"))
                    .Field(new Field("User.DepartmentCode").Options(new Options()
                            .Label(new[] { "DepartmentName" })
                    .Field(new Field("Department.DepartmentName"))
                    .LeftJoin("Department", "User.DepartmentCode", "=", "Department.DepartmentCode");

                editor.PostCreate += (sender, e) => {

                var response = editor.Process(request).Data();

                return Json(response);

Inside of SendUserActivationEmail, I can see the ID of the newly inserted record, but it seems the record is not committed to the database yet and the User table is locked, so the read with ID went timeout. I'm wondering if there is a way for postCreate to be triggered after the DB operation is completed. Thanks!

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.


  • shuminliushuminliu Posts: 10Questions: 4Answers: 0

    I also tried the WriteCreate handler but still no luck :(

  • allanallan Posts: 56,849Questions: 1Answers: 9,035 Site admin

    It will be because Editor uses a transaction by default - add .Transaction(false) just before the .Process(...) call and it should work.

    Alternatively, you can access the transaction that Editor is using with the Editor.DbTransaction() method. Carry out your queries on that and it should work.


This discussion has been closed.