3.6 to 4.5: Has DataPortal.UpdateChild changed?

3.6 to 4.5: Has DataPortal.UpdateChild changed?

Old forum URL: forums.lhotka.net/forums/t/12201.aspx

Tom_W posted on Thursday, October 31, 2013



I've been working through migrating a small 3.6.3 project to 4.5.40.  I've got readonly objects returning, and CRUD working on editable roots, but I'm having problems with their child editable lists.

The class is declared as:

public partial class CrewMemberER : MyBusinessBase<CrewMemberER>

Where MyBusinessBase inherits from Jonny's Csla.Validation.BusinessBase<T>.


The update method is then:

       #region Data Access - Update


              protected override void DataPortal_Update()


                     bool cancel = false;

                     OnUpdating(ref cancel);

                     if (cancel) return;

                     using (var mgr = ContextManager<Core.Data.Linq.BASE_PROJECTDataContext>



                           var data = new Core.Data.Linq.CREW_MEMBER()


                                  CrewMemberId = ReadProperty(CrewMemberIdProperty)


                           data.LastChanged = _lastChanged;


                           if (IsSelfDirty)


                                  data.TitleId = ReadProperty(TitleIdProperty);

                                  data.FirstName = ReadProperty(FirstNameProperty);

                                  data.LastName = ReadProperty(LastNameProperty);

                                  data.Notes = ReadProperty(NotesProperty);

                                  data.DateEntered = ReadProperty(DateEnteredProperty);

                                  data.EnteredById = ReadProperty(EnteredByIdProperty);

                                  data.LastChangedById = Security.ApplicationPrincipal.CurrentApplicationIdentity.UserContactId.Value;

                                  data.IsCurrentOption = ReadProperty(IsCurrentOptionProperty);

                                  data.LegacyId = ReadProperty(LegacyIdProperty);

                                  mgr.DataContext.CREW_MEMBERs.Attach(data, true);


                           //Update Child object(s)

                           DataPortal.UpdateChild(ReadProperty(CrewMemberVaccinationECLProperty), this);

                           DataPortal.UpdateChild(ReadProperty(CrewMemberHotelECLProperty), this);



                           if (IsSelfDirty)


                                  _lastChanged = data.LastChanged.ToArray();






The actual exception is:


System.InvalidCastException occurred


  Message=Unable to cast object of type 'Core.Business.Library.Crew.CrewMemberER' to type 'Core.Business.Library.Crew.CrewMemberVaccinationECL'.

  Source=Anonymously Hosted DynamicMethods Assembly


       at lambda_method(Closure , Object , Object[] )

       at Csla.Reflection.MethodCaller.CallMethod(Object obj, DynamicMethodHandle methodHandle, Boolean hasParameters, Object[] parameters) in c:\Program Files (x86)\Marimer LLC\CSLA .NET\4.5.40\Source\Csla\Reflection\MethodCaller.cs:line 524



Which seems to suggest I shouldn't be passing 'this' to the UpdateChild method?  These update scripts are based on the linq2sql based templates so to be honest I don't completely understand why the parent is being passed in in the first place.  


Is there an obvious answer to this?




Tom_W replied on Thursday, October 31, 2013

Well, I solved it by taking the second 'this' parameter out and that seemed to get it working correctly.  Not sure why it was there in the first place.

JonnyBee replied on Friday, November 01, 2013

DataPortal.UpdateChild code hasn't changed but MethodCaller has seen some updates in how it determines which method to call based on the parameters supplied. 

So I believe this is the difference. 

Tom_W replied on Friday, November 01, 2013

Ahhhh... that makes sense.  Right, I'll have a read up on that and see if that has ramifications for code elsewhere too.  Thanks for your help Jonny.


Copyright (c) Marimer LLC