Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

13. Creating and Using POCO Entities > Using Proxies to Enable Change Notificat...

Using Proxies to Enable Change Notification, Lazy Loading, and Relationship Fix-Up

As you read earlier, DetectChanges also forces the context to update the ObjectStateEntry objects that it uses for change tracking. When you call DetectChanges, the context takes a snapshot of the current state of the entities.

It is possible to force the entities to notify the context of changes so that you don’t have to wait until you (or the SaveChanges method) call DetectChanges.

You can do this by using a special feature of Entity Framework that enables classes to be wrapped by a special proxy class at runtime. To use this, you must mark every property in the class as virtual. In VB, this is Overridable. At runtime, Entity Framework uses reflection to discover that you have marked the properties as virtual and it will create a DynamicProxy class on the fly, then force it to inherit from your entity. This proxy will add functionality to the runtime POCO class that has many of the same features as an EntityObject. But as you’ll see further on, it is not an EntityObject. It is something completely different.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint