FieldManager.FieldExists method always returns true after Save

FieldManager.FieldExists method always returns true after Save

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


basile posted on Wednesday, January 07, 2009

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.

RockfordLhotka replied on Wednesday, January 07, 2009

To be sure I understand:

  1. You have a parent object, with a lazy loaded child property.
  2. This property is never retrieved or set and so doesn't "exist"
  3. Your data access code doesn't access the property
  4. After the save operation the property "exists"

How are you saving your child objects? Using the field manager helper method?

basile replied on Wednesday, January 07, 2009

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!

basile replied on Wednesday, January 07, 2009

Yes! Wrapping the DataPortal.UpdateChild call for the lazy-loaded child property inside of a if(FieldManager.FieldExists(ChildCollectionProperty)){...} block fixed the issue.

RockfordLhotka replied on Wednesday, January 07, 2009

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.



RockfordLhotka replied on Wednesday, January 07, 2009

That’s my guess as well, and if you can confirm it that’d be great! Thank you!

 

Rocky

ajj3085 replied on Thursday, January 08, 2009

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.

basile replied on Thursday, January 08, 2009

@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 :(

ajj3085 replied on Thursday, January 08, 2009

Ahh, I see.  Thanks for that info, I was curious how it would work myself.

RockfordLhotka replied on Thursday, January 08, 2009

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 :(



basile replied on Thursday, January 08, 2009

OK, thanks for the information, we are already started wrapping all lazy-loaded property UpdateChild calls inside of FieldManager.FieldExists blocks

Copyright (c) Marimer LLC