Print Page | Close Window

EntityManagerDelegate

Printed From: IdeaBlade
Category: Cocktail
Forum Name: Community Forum
Forum Discription: A professional application framework using Caliburn.Micro and DevForce
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=4274
Printed Date: 20-Sep-2025 at 4:27am


Topic: EntityManagerDelegate
Posted By: jkattestaart
Subject: EntityManagerDelegate
Date Posted: 16-Aug-2013 at 3:00am
Marcel,

I want to update a related entity on saving.

This is the code (just after the assign of then

          var entity = args.Entities.OfType<Booking>()
                      .FirstOrDefault(e => e.EntityAspect.EntityState.IsAddedOrModified());

          if (entity != null)
            UpdateBookingReminders(entity, args);
        }


        private void UpdateBookingReminders(Booking booking, EntitySavingEventArgs args)
        {
          var payments = booking.BookingPayments;
          BookingPayment payment;

          foreach (var reminder in booking.BookingReminders)
          {
            if (reminder.Milestone == "DEPARTURE")
            {
              var due = booking.departure.AddDays(reminder.offset);
              reminder.SetValue("Due", due);                          
              args.Entities.Add(reminder);
              reminder.EntityAspect.SetModified();
            }

But is doesn't seem to update anything. What am i doing wrong.

BTW i am using cocktail 1.0



Replies:
Posted By: smi-mark
Date Posted: 16-Aug-2013 at 7:50am
Would this logic not be better on the server than on the client? In the SaveInterceptor on the ExecuteSave you could execute this logic then call base.ExecuteSave() and it should work.


Posted By: mgood
Date Posted: 16-Aug-2013 at 8:19am
Not sure at the moment what's going on. Try these. Instead of calling SetValue, why don't you just assign the due data? reminder.Due = due. That should already set the entity to modified, so then you can skip the call to SetModified. Set a breakpoint and make sure the Due data was actually changed and that the entity is in modified state.

Marks suggestion is also a good. This doesn't necessarily have to be done on the client.


Posted By: jkattestaart
Date Posted: 16-Aug-2013 at 9:56am
Tried also to set the values directly.
When i debug the values seem to be ok.

I will try marks suggestion also.

thanks.


Posted By: jkattestaart
Date Posted: 16-Aug-2013 at 1:21pm
Sorry guys, it was my code that failed.

I did set my value (which was wat i saw in de debugger), but i overlooked the rest of my code.

But it is good to know where to put my code.



Print Page | Close Window