I was wondering if anyone has attempted to lazy load a subclass (where is isn't known what the subclass is until the resul开发者_如何转开发t is returned) using EF and POCOs?
This is a bit of a nightmare in NHibernate, but works as long as you don't attempt to cast the returned result to a subclass (because a proxy of the base class is created, it can't be cast).
If you are talking about casting a property to a specific derived type or a specific interface implementation, no, it cannot be done, and IMHO it shouldn't be done. If a property is supposed to return an implementation of a specific interface, then you should communicate with it through that interface. Casting is usually a sign you are doing something wrong.
Otherwise properties are lazy loaded on access without problems (if they are configured to lazy load).
You may want to expand on "where it isn't known what the subclass is until the result is returned" but...
I've been using Lazy Loading in EF 4 w/ POCOs and everything works smooth as butter. Everything is populated when I need it with no code from me.
精彩评论