FieldManager.UnsetProperty?

FieldManager.UnsetProperty?

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


ajj3085 posted on Thursday, September 24, 2009

Hi,

I have an scenario where a BO has a field which may contain a lot of binary data. I'm trying to reduce the size of the BO on the wire, which to the server can't be done... but once the binary data is in the database, I'd like to unset the field so that the binary data doesn't come back with the BO. This property can be lazy loaded, so if its actually used on the client it will be loaded then.

I tried using LoadProperty( Property, null ), but lazy loading then breaks, presumably because FieldManager.FieldExists returns true.

Is there anyway to "unset" a field after it's been accessed?

JonnyBee replied on Thursday, September 24, 2009

Hi Andy,

This is already registered on the wishlist for Csla.
http://www.lhotka.net/cslabugs/edit_bug.aspx?id=540

For now - your lazy loading must check if both FieldManager.FieldExists and the property value is null. 

/jonnybee

ajj3085 replied on Thursday, September 24, 2009

Ok, thanks to both of you for your responses. I'll add the null check too.

rsbaker0 replied on Thursday, September 24, 2009

I ran into similar issues trying to create custom IFieldData implementations -- all the good stuff in FieldDataManager is private or internal. I finally had to make GetFieldData() public, but that won't solve your problem.

FieldExists returns true if the _fieldData[] slot for the property has any value in it, whether the actual data value wrapped by the IFieldData reference is null or not.

There is even a "RemoveField" function (still internal), but it just sets the wrapped value to null and doesn't remove the IFieldData itself, so FieldExists will still return true after RemoveField() is called.

As a practical matter, I think you just need a way to set _fieldData[property index] = null, but there isn't a way to do that in 3.5 without changing CSLA. I think it would be fairly simple addition (undo issues aside).

With my lazing loading implementation, I just ended up setting the property value to null, and I test for that and reload if either FieldExists is false or Get/ReadProperty() returns null.

Copyright (c) Marimer LLC