Feature Request for Updatexxx Method

Hello Radzen Team,
sometimes i need to compare various properties of model classes/objects before or after whenever they are updated. This is hard to do in Radzen.
It was great if the generated code for the Updatexxx Method in the DBService class will give the new item AND the actual database item into the OnxxxUpdated and OnAfterxxxUpdatec partial methods.

Like this:

    partial void OnAngebotUploadDatumUpdated(Models.Trentdb.AngebotUploadDatum item, Models.Trentdb.AngebotUploadDatum itemToUpdate);
    partial void OnAfterAngebotUploadDatumUpdated(Models.Trentdb.AngebotUploadDatum item, Models.Trentdb.AngebotUploadDatum itemToUpdate);

    public async Task<Models.Trentdb.AngebotUploadDatum> UpdateAngebotUploadDatum(int? angebotUploadDataId, Models.Trentdb.AngebotUploadDatum angebotUploadDatum)
    {
        var itemToUpdate = context.AngebotUploadData
                          .Where(i => i.AngebotUploadDataId == angebotUploadDataId)
                          .FirstOrDefault();
        if (itemToUpdate == null)
        {
           throw new Exception("Item no longer available");
        }

        OnAngebotUploadDatumUpdated(angebotUploadDatum, itemToUpdate);

        var entryToUpdate = context.Entry(itemToUpdate);
        entryToUpdate.CurrentValues.SetValues(angebotUploadDatum);
        entryToUpdate.State = EntityState.Modified;
        context.SaveChanges();

        OnAfterAngebotUploadDatumUpdated(angebotUploadDatum, itemToUpdate);

        return angebotUploadDatum;
    }

What do you think about it? It is helpful for so many things i think.
E.g. i like to implement a "History" of some kind of Changes made to the Data. This is very easy to do when new and old data can be compared in the partial methods.
And so much more...

Kind regards
Thomas

I am afraid that we can't do that as it will be a breaking change for every application that specifies OnXXXUpdated at the moment.

hi @korchev,
I understand... too bad :thinking:

And what if the "compare" function are new partial methods?

Like ths:

partial void OnAngebotUploadDatumUpdated(Models.Trentdb.AngebotUploadDatum item);
partial void OnAfterAngebotUploadDatumUpdated(Models.Trentdb.AngebotUploadDatum item);
partial void OnAngebotUploadDatumUpdatedCompare(Models.Trentdb.AngebotUploadDatum item, Models.Trentdb.AngebotUploadDatum itemToUpdate);
partial void OnAfterAngebotUploadDatumUpdatedCompare(Models.Trentdb.AngebotUploadDatum item, Models.Trentdb.AngebotUploadDatum itemToUpdate);

public async Task<Models.Trentdb.AngebotUploadDatum> UpdateAngebotUploadDatum(int? angebotUploadDataId, Models.Trentdb.AngebotUploadDatum angebotUploadDatum)
{
    OnAngebotUploadDatumUpdated(angebotUploadDatum;
    var itemToUpdate = context.AngebotUploadData
                      .Where(i => i.AngebotUploadDataId == angebotUploadDataId)
                      .FirstOrDefault();
    if (itemToUpdate == null)
    {
       throw new Exception("Item no longer available");
    }

    OnAngebotUploadDatumUpdatedCompare(angebotUploadDatum, itemToUpdate);

    var entryToUpdate = context.Entry(itemToUpdate);
    entryToUpdate.CurrentValues.SetValues(angebotUploadDatum);
    entryToUpdate.State = EntityState.Modified;
    context.SaveChanges();

    OnAfterAngebotUploadDatumUpdated(angebotUploadDatum);
    OnAfterAngebotUploadDatumUpdatedCompare(angebotUploadDatum, itemToUpdate);

    return angebotUploadDatum;
}

Dont want to discuss if you are generally against the feature. Just having an idea to avoid a breaking change.

Kind Regards
Thomas

Just running into a problem that will be solved easily with this feature :sweat_smile:

We don't want to add two more partial methods. What exactly are you trying to solve?

hi @korchev,
i have several situations where data changes must trigger other data changes (some are really complex).
for example.. whenever a user changes the status of a project (Table Projekt, Property, int ProjektStatusId) i must refresh/recalculate several other datasources/tables because their status and other properties (like an amount property which must be recalculated) depends on which Status the user has changed to the new Status. The Status can be changed in several Pages. So the pages are not the right location to implement these business logic.
This must be done whenever the Status changes. There are complex routines that must be executed.

For sure someone can say... do it in the database... but this cant be the solution. Doing so i move program/business logic to the Database. That is not the right place cause its database dependend code that propbably works only in Oracle OR Sql Server OR some other Databases. i dont want to create code which depends on the database system. This is inconsistent to the basic idea of EF.
So i must (and will) implement code in my apps business logic.

The question in such a system is...
Where can i implement these "Whenever a table property data changes no matter where... i must execute other business logic" things?
in my opinion the "Upadtexxx..." are the right places to achieve this. But this can only be done when i know the OldValue and the NewValue.
And i have no idea how this can be done (without great effort) in radzen without the feature requested.
The only thing a can imagine is to reload the "Old or in the database stored item" like radzen do it in the OnxxxxUpdated methods. But this is done twice... radzen loads the item... and i load it again in the my partial method. Not so optimal.
And... the business logic depends on the data in the database (new Status is updated in the database). this can only be done in the OnAfterUpdate.... partial method. But at this moment the OldValue is overritten and gone. I cant compare Old and New.
I can imagine how to "save" the OldValue in the OnxxxUpdated" method but this is quite an effort.
So i thought... radzen has the data in the Update method. So why dont use it with a small change in the generated code?
Thats why i asked for this feature.
It has a great potential for many demands based on "Whenever i change data form this value to another value i must do something"

Thanks for reading.

Kind Regards
Thomas

You can use Entity framework for that. Check our Audit Trail example. You can handle changes to all entities in one single place without creating partial methods per class.

The change is not small as it will break all applications that use partial methods. We can't do that.

Ah! Ok. I will have a look at this! Thank you!

Yes. Sure. I didnt realized that when i thought about the feature request. After you explain it in the first reply it was clear that this will be a breaking change :slight_smile:

Overall... Thank you for helping out with the hint to the Audit Trail example!

Kind Regards
Thomas