Implement uow.AddUpdateMultiCall() with existing InitClassEmpty()

Posts   
 
    
SanderF
User
Posts: 125
Joined: 11-Dec-2006
# Posted on: 14-Jul-2008 14:44:28   

Hi,

I would like to update a lot of records via a uow.AddUpdateMultiCall(). In this situation i need to add an entity with the values to be updated. So i write:

ActieEntity newValuesVervolg = new ActieEntity();
newValuesVervolg.VervolgActieID = null;

ActieCollection acties = new ActieCollection();
uow.AddUpdateMultiCall(acties, newValuesVorige, ActieFields.VorigeActieID == ID);

The problem is that the InitClassEmpty() of the ActieEntitiy is filled with:

protected override void InitClassEmpty(IValidator validatorToUse)
{
    base.InitClassEmpty(validatorToUse);
    if (Fields.State == EntityState.New)
    {
        Datum = DateTime.Today;
        Gereed = false;
    }
}

We need to add this code in the InitClassEmpty() because the initial values must be refelected in the webpage directly when we create a new record (when we put this in the OnSave() we can't see the initial values).

When i commit the UnitOfWork i see that the following values will be set: - Datum (because of InitClassEmpty()) - Gereed (because of InitClassEmpty()) - and the field VervolgActieID.

The problem is that the values of "Datum" and "Gereed" may not be updated in the UnitOfWork.

Can you tell me what i'm doing wrong?

Regards, Sander

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 14-Jul-2008 15:19:28   

Would you please check the IsChanged property value of each of these entityField?

SanderF
User
Posts: 125
Joined: 11-Dec-2006
# Posted on: 14-Jul-2008 17:14:04   

When i query during runtime:

newValuesVorige.Fields["Gereed"].IsChanged

than "True" is returned...

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 14-Jul-2008 17:53:45   

Please try forcing this fieldsd to IsChanged false.

ActieEntity newValuesVervolg = new ActieEntity();
newValuesVervolg.VervolgActieID = null;
newValuesVervolg.Fields["Datum"].IsChanged = false;
newValuesVervolg.Fields["Gareed"].IsChanged = false;

ActieCollection acties = new ActieCollection();
uow.AddUpdateMultiCall(acties, newValuesVorige, ActieFields.VorigeActieID == ID);
David Elizondo | LLBLGen Support Team
SanderF
User
Posts: 125
Joined: 11-Dec-2006
# Posted on: 14-Jul-2008 20:25:28   

When i set the IsChanged property to false in the OnDelete()-methode and we add a new field to the InitClassEmpty() method in that entity, we can't see we need to add the

Fields["NewField"].IsChanged = false;

statement into the OnDelete()-methode to get the same result. When we add the IsChanged-statement directly into the InitClassEmpty() the fields will not be saved in the database.

Is there another work-around / solution for this problem?

Thanks, Sander

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 15-Jul-2008 07:07:33   

daelmo wrote:

Please try forcing this fieldsd to IsChanged false.

ActieEntity newValuesVervolg = new ActieEntity();
newValuesVervolg.VervolgActieID = null;
newValuesVervolg.Fields["Datum"].IsChanged = false;
newValuesVervolg.Fields["Gareed"].IsChanged = false;

ActieCollection acties = new ActieCollection();
uow.AddUpdateMultiCall(acties, newValuesVorige, ActieFields.VorigeActieID == ID);

What I tried to say is that you should force the IsChanged property of the problematic fields right before you call AddUpdateMultiCall, not at the InitClassEmpty().

Forcing this will avoid the Datum and Gareed fields being updated, as the problem is, as far as I understood from your first post. Or did I misunderstood that?

BTW, I never mentioned OnDelete() simple_smile

David Elizondo | LLBLGen Support Team
SanderF
User
Posts: 125
Joined: 11-Dec-2006
# Posted on: 15-Jul-2008 13:54:20   

You're right, you've never mentioned OnDelete(), but that is the place where i need the UnitOfWork simple_smile

I've made a helperclass with a method SetAllFields2NotChanged() which sets all the IsChanged-properties of the fields to false.

public static void SetAllFields2NotChanged (CommonEntityBase entity)
{
    foreach (EntityField field in entity.Fields)
        field.IsChanged = false;
}

I call this method directly after i create a new entity.

ActieEntity newValuesVervolg = new ActieEntity();
SetAllFields2NotChanged(newValuesVorige);
newValuesVervolg.VervolgActieID = null;

ActieCollection acties = new ActieCollection();
uow.AddUpdateMultiCall(acties, newValuesVorige, ActieFields.VorigeActieID == ID);

This works fine for me, thanks for the advice!

Regards, Sander