0

I have the need to perform some custom logic in my EF 4 STE public getters and setters. However, I only want this custom logic to execute if EF is not currently hydrating an entity.

Are there any built in flags, statuses or object states that can be checked to determine if EF is currently in the act of hydrating a STE entity on my behalf?

I am not doing lazy loading, so we perform all our data loading in one shot. I'm hoping I don't have to change the Entity T4 templates to add the infrastructure to track this stuff myself.

Thanks, Nate

Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480
Nate Jackson
  • 549
  • 4
  • 15

1 Answers1

0

No there is no such flag but you can try to do it this way:

  • Define interface for all your STEs with methods SavingStarted, SavingFinished
  • Implement these methods in STE template to be ablet to turn your flag on and off
  • Modify getters and setters definition in STE template to work with flag
  • Override SaveChanges on your ObjectContext.
  • Iterate through modified entities which are convertible to your interface and call SavingStarted
  • Call base.SaveChanges
  • Again iterate through that entities and call SavingFinished

The only problem is that these methods will be part of STE's public interface. To avoid this you can implement these methods in ObjectContext and access STE's internal property with flag. This is possible only when STEs and ObjectContext are in the same assembly or InternalsVisibleTo is used.

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670