Print Page | Close Window

EntityAspect.Wrap always returns the same instance

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3155
Printed Date: 13-May-2026 at 1:59pm


Topic: EntityAspect.Wrap always returns the same instance
Posted By: WardBell
Subject: EntityAspect.Wrap always returns the same instance
Date Posted: 13-Dec-2011 at 10:05am
The question as received:

Do repeated calls to EntityAspect.Wrap() for a POCO return the same EntityAspect instance? I'm thinking it must, but it's not clear from the documentation.

 

Also, I assume that if you implement IHasPocoEntityAspect, it grabs the EntityAspect from there. The doc makes it sound like to access the EntityAspect on a POCO, it's either EntityAspect.Wrap() or IHasPocoEntityAspect. With the last paragraph you can kinda infer that the two work in conjunction, but it's not spelled out.

The answer:

EntityAspect.Wrap will always return the same EntityAspect instance for a given entity, regardless of whether a it is a regular EF-mapped entity or a poco entity.

 

If you implement IHasPocoEntityAspect then this provides the ‘backing’ for the EntityAspect for a given entity, otherwise the relation between the entity and its EntityAspect is stored in a global WeakRefDictionary.

 

The EntityAspect.Wrap method observes these distinctions and responds accordingly.

 



Print Page | Close Window