views:

30

answers:

2

I was wondering if anyone has attempted to lazy load a subclass (where is isn't known what the subclass is until the result 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).

+1  A: 

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.

Justin Niessner
+1  A: 

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).

Groo
It's a fair point and I have changed my code so that it doesn't attempt to cast to the subclass. Thanks
Ross Scott