We use a FieldManager.FieldExists check within our business classes to lazy-load some child properties, but after upgrading to CSLA 3.6 we noticed that the method always returns true after the root object has been saved.
To be sure I understand:
How are you saving your child objects? Using the field manager helper method?
1. Correct, we have a root object and a lazy-loaded collection of child objects property
2. Correct
3. We use DataPortal.UpdateChild(ReadProperty<ChildCollection>(Children), this, cn) method call to update the child collection - this may be where the issue is...
4. Correct, the FieldManager.FieldExists method returns true, but the property value is null since it was never loaded
Seems like our problem is related to DataPortal.UpdateChild call for the lazy-loaded property. I'll verify and post an update.
Thanks!
Yes! Wrapping the DataPortal.UpdateChild call for the lazy-loaded child property inside of a if(FieldManager.FieldExists(ChildCollectionProperty)){...} block fixed the issue.
Ok, I’ll add a bug to the tracker so this gets fixed –
thanks!
From: basile
[mailto:cslanet@lhotka.net]
Sent: Wednesday, January 07, 2009 3:39 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] FieldManager.FieldExists method always returns
true after Save
Yes! Wrapping the DataPortal.UpdateChild call for the lazy-loaded
child property inside of a
if(FieldManager.FieldExists(ChildCollectionProperty)){...} block fixed the
issue.
That’s my guess as well, and if you can confirm it that’d
be great! Thank you!
Rocky
basile:3. We use DataPortal.UpdateChild(ReadProperty<ChildCollection>(Children), this, cn) method call to update the child collection - this may be where the issue is...
What if you did:
FieldManager.UpdateChildren( this, cn );
Does that have the same effect? Just curious.
@ajj3085: I just tried using FieldManager.UpdateChildren(this, cn) and it is working properly for lazy-loaded properties and is not causing the mentioned issue. Unfortunately, we aren't able to use this method since DataPortal method signatures are not the same for all of the child properties :(
Ahh, in that case this isn’t a bug with CSLA – it is
a bug with your code. I didn’t immediately follow what you were doing.
When you manually call the DataPortal method, you are accessing
the field in your code – which triggers the creation of the field. So you
do need to wrap that code with an exists check to avoid the issue. There’s
really nothing CSLA can do for you in that case.
Rocky
From: basile
[mailto:cslanet@lhotka.net]
Sent: Thursday, January 08, 2009 7:56 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] FieldManager.FieldExists method always returns
true after Save
@ajj3085: I just tried using FieldManager.UpdateChildren(this, cn) and
it is working properly for lazy-loaded properties and is not causing the
mentioned issue. Unfortunately, we aren't able to use this method since
DataPortal method signatures are not the same for all of the child properties
:(
Copyright (c) Marimer LLC