Update Properties with values from database without creating infinite loop on Child_Changed event.

Update Properties with values from database without creating infinite loop on Child_Changed event.

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


cwinkelmann posted on Monday, April 02, 2012

Once again relying on the expertise of the CSLA community...

I have a parent / child collection / grandchild collection object graph. When any of the child, grandchild objects change it calls the Child_Changed event where the parent object will call Save() which calls FieldManager.UpdateChildren();

When any of the children are saved, the trip to the database invokes an SP which has output parameters like TimeStamp, (if new then the object Database Identity), and some occasional text fields that will revert to defaults. The problem is the BusinessBase does not expose BypassPropertyChecks as it is "internal" and also the method "MarkOld()" is "protected" so I'm not sure if there is any support native to CSLA to allow a DAL assembly to load properties of the BusinessBase...

I can write methods that accept parameters of the values that come back from the SP and then the BusinessBase class can set the internal "private backing fields" or use LoadProperty(),,,, BUT is there any support or design in CSLA to load values from an external process?

 

Thanks greatly as always for your expertise! :-)

cwinkelmann replied on Tuesday, April 03, 2012

Poring over the search results I found something that has potential!!!!

 

 

http://forums.lhotka.net/forums/p/171/1001.aspx#1001

malloc1024 replied on Fri, May 26 2006 12:06 PM

rated by 0 users

Why not use a separated interface approach instead of DTOs?  This will allow you to load the object directly from the DAL.  The trick, use explicit interfaces instead on implicit interfaces.  Create an explicit interface for each object and add them to the DAL.  Have each object implement their respective interface.  Add a LoadingFromDAL flag to each interface.  Setting this flag before loading an object will allow you to load your object directly without evoking broken rules, MarkDirty etc.  Further, it also allows you to load ReadOnly properties.  Using explicit interfaces will also allow you to load private properties from the DAL.   The only way to access these private properties (not including reflection) is through casting to the interface. However, since the interface resides in the DAL, the presentation layer will never be able to access these private properties.  Using explicit interfaces solves most of the problems that are associated the separated interface method.  Does anyone see any potential problems with this?

 

 

This is pretty much what I need, but I have some coding to do. The last thing I need is an update to occur and then the DAL having to pass back a value which triggers an update while the DAL is still updating the BB.

 

I would love to see other comments on how people prefer the interface to work. Pass a DAL and let the object load output values, or pass each value???

 

JonnyBee replied on Tuesday, April 03, 2012

Use the ObjectFactory base class to create an accessor class.

This will allow f.ex MarkOld and LoadProperty from external class.

Copyright (c) Marimer LLC