This is a migrated thread and some comments may be shown as answers.

Newbie question

2 Answers 80 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Chris
Top achievements
Rank 1
Chris asked on 28 Feb 2009, 08:20 AM
I'm sure this is in the docs somewhere, but I've just spent two hours trying to find it.  If anyone could point me in the right firection i would really appreciate it.

All I want to do is iterate iterate over some data in a many to many collection, i.e. dump every person and all their addresses.

I'm trying something like this:

Dim scope As Telerik.OpenAccess.IObjectScope
        scope = OaMsTest1.ObjectScopeProvider1.GetNewObjectScope
        scope.Transaction.Begin()
        Dim ext As IQueryable(Of Person)
        ext = scope.Extent(Of Person)()

        Dim result = From person In ext _
                     Select person

        Dim adds As New List(Of Address)      

        For Each p In result              'Loop through all People
            adds= p.Addresses           'Does NOT work. Can not convert it to a list
            Console.WriteLine(p.LastName)
            For Each address In p.addresses      'Loop through all addresses for this person
                Console.WriteLine("   " & address.StreetName)
            Next
        Next

Shouldn't it just lazy load the collection when it is referenced? Is there a way to explicitly load it, like p.Addresses.LoadAll ??

Thanks,

2 Answers, 1 is accepted

Sort by
0
Jan Blessenohl
Telerik team
answered on 02 Mar 2009, 09:26 AM
Hello Chris,
OpenAccess uses lazy loading. Because the normal .NET List type does not support hooks we have our own internal list implementation. The difference in your code is that you can only use the List interface IList for accessing the collections.

Dim adds As New IList(Of Address)

should work.

All the best,
Jan Blessenohl
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Chris
Top achievements
Rank 1
answered on 08 Mar 2009, 04:15 AM
Thanks for the tip.
I spent a little more time looking at the error and realized it was being thrown in the property, not the actual line of code I indicated.  I made the change you recommended and fixed my classes properties  to use IList(of T) and it seems to work fine.
Tags
General Discussions
Asked by
Chris
Top achievements
Rank 1
Answers by
Jan Blessenohl
Telerik team
Chris
Top achievements
Rank 1
Share this question
or