c# - self tracking pocos, how to tell if a property has changed? -
((iobjectwithchangetracker)user).changetracker.state
seems give me "unchanged" every time. when call applychanges picked properly, able make determination in business layer on whether has changed particular property, if did want perform action.
updated
i believe has fact don't serialize entities triggers change tracking. using them in asp.net scenario time time persist them (serialize) session state or viewstate.
updated
added more information in answer @ bottom of page.
several options, each ups , downs:
you keep private "original" value on domain objects. populate them when object db, , can check if each field equals original value. cumbersome on large objects, however.
another option have domain implement icloneable, , keep deep copy of original object in data access layer, along logic pull up. deep copy still mutable, have take care not modify it, , doubles memory footprint.
you re-retrieve record new instance, , check fields. simple , relatively straightforward, requires 2 trips db.
lastly, if you're using orm nhibernate, can plug logic uses determine data has changed. best place auditing , other observational behaviors on domain layer, requires use of orm supports this, , you'll have limited ability change data.
Comments
Post a Comment