Newbie question

Thread is closed for posting
3 posts, 0 answers
  1. Chris
    Chris avatar
    23 posts
    Member since:
    Feb 2009

    Posted 28 Feb 2009 Link to this post

    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. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 02 Mar 2009 Link to this post

    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.
  3. Chris
    Chris avatar
    23 posts
    Member since:
    Feb 2009

    Posted 07 Mar 2009 Link to this post

    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.
Back to Top