New Posts New Posts RSS Feed: EntityManagerDelegate
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

EntityManagerDelegate

 Post Reply Post Reply
Author
jkattestaart View Drop Down
Newbie
Newbie


Joined: 30-Jul-2010
Location: Netherlands
Posts: 37
Post Options Post Options   Quote jkattestaart Quote  Post ReplyReply Direct Link To This Post Topic: EntityManagerDelegate
    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

Edited by jkattestaart - 16-Aug-2013 at 4:30am
Back to Top
smi-mark View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
Post Options Post Options   Quote smi-mark Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
jkattestaart View Drop Down
Newbie
Newbie


Joined: 30-Jul-2010
Location: Netherlands
Posts: 37
Post Options Post Options   Quote jkattestaart Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
jkattestaart View Drop Down
Newbie
Newbie


Joined: 30-Jul-2010
Location: Netherlands
Posts: 37
Post Options Post Options   Quote jkattestaart Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down