You are right, given an object, we don't know what context it belongs to, or what session it is attached to. But Lazy Loading happens like this :
var firstPost = _Context.Posts.First()
var commentList = firstPost.Comments
When you say _Context.Posts.First()
then one post is loaded.
Then when you say firstPost.Comments
that's when the comments list is loaded.
This is possible because the type of your Comments field in your Post is probably an IList
or some such generic interface : this is because EF4 can put a proxy list instead of the actual comment list. The proxy list knows about the _Context - knows about which session or context it is attached to. Hence it is able to load an actual list on demand.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…