Search code examples
c#devexpressxafxpo

How to update value of a record in XAF, using Oid, from a custom form?


I need to update value of a record in DevExpress XAF, from a custom form, if Oid of a record matches the input I am getting from a textbox.

I have tried using UnitofWork by the following code, but it doesn't work:

        UnitOfWork uow = new UnitOfWork();

        CriteriaOperator op = CriteriaOperator.Parse("Oid = ?", ReceivedTextBox.Text);
        Bilty bilty = uow.FindObject<Bilty>(op);

        if (bilty == null) return;
        bilty.Received = true;

        uow.CommitChanges();

Can someone tell me what I am doing wrong here? I have tried searching for the solution on official DevExpress forum but this is the best I could reach.


Solution

  • I guess the problem is with the UnitofWork connection. The code you posted implies that the default datalyer is used, therefore xpo will create an new AccessDb for the default datalayer and will search for the object which of course cannot be found as this is an empty database. Since you have not posted details on where this custom form lives, I assume it is on the same Xaf application, and you used an action to display it. Therefore I suggest you pass the Xaf application instance to your form and create an objectspace

    objectspace=application.CreateObjectSpace()

    use that objectSpace to query and update the record instead of the UnitOfWork.