Ok findings so far (I'll quit now, the Leffe Blond beer is getting into my brain too much now
)
(I did selfservicing today, which is harder than adapter, due to the lazy loading)
- the error I got was caused by the lazy loading code which got executed and threw an exception, which resulted in the 'Specified method is not supported' error which is of no use to ANYONE on this planet but thanks to the debugging help Bert gave, I caught that one.
- I implemented ICustomTypeDescriptor on EntityBase and EntityBase2. This solved the problem for webgrids where all kinds of properties show up in teh grids. This will be solved by this.
- I implemented IListSource and IComponent on EntityCollectionBase. This went ok, but it caused an infinite loop
- The loop was caused by the fact that Microsoft implemented incredible crappy code in vs.net for determining the IList's in a bound list: it calls ITypedList.GetItemProperties() a gazillion times and doesn't cache results, so it doesn't determine apparently if a collection is already seen. This causes problems with for example m:n relations which loop forever, or relations with self. After all kinds of caching mechanisms I gave up and implemented a path length if 1 as maximum (that's actually 2, but don't ask, it's ITypedList logic...)
This worked! I could drag a normal CustomerCollection on a form, bind it to a grid and when I clicked DataMember, I save 'Employees' Orders, Etc... and when I clicked open Employees I could select EmployeeEntity's collections as well
It was very slow though (or this might be the debugger, don't know), so some sort of caching has to be implemented somewhere (took 1 second to get the list). The key is in DataViewManager, a class which is returned by DataSet.GetList() (the IListSource implementation of DataSet) and DataViewManager caches the property descriptors etc.
I now need to implement some sort of way to tell an entity to switch off lazy loading when in design mode (but that's not that hard
) even if it's in a subcollection somewhere, and some more caching of property descriptors and IListSource lists to prevent loops.
Anyway, we're almost there, and it's even better than I'd hoped for. No extra object needed, just the entitycollections. After all the frustration with this, I can say, I'm very happy
I too have the duplicate datasource item in DataSource. I don't know why that's done... Perhaps the IComponent itself and the IListSource.GetList() returned instance (which is the same), dunno.
Tomorrow I'll try to wrap this up and grab John's code to get adapter on track, which is IMHO easier to do, now I know this.
OK, as soon as some code + templates are runnable, I'll release them on the site for testing, which is pretty straight forward. The templates I change with Template Studio, so it's also a good testcase