views:

15

answers:

0

I have this class declaration:

Public Class clsColection(Of T)
     Inherits System.Collections.ObjectModel.KeyedCollection(Of String, T)
     Implements System.Collections.IEnumerable
     Implements System.Collections.Generic.IEnumerable(Of T)

...

Public Shadows Function GetEnumerator() As System.Collections.Generic.IEnumerator(Of T) Implements System.Collections.Generic.IEnumerable(Of T).GetEnumerator
    LoadIfRequired()
    Return DirectCast(MyBase.GetEnumerator(), System.Collections.Generic.IEnumerator(Of T))
End Function

Public Shadows Function GetEnumerator1() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
    LoadIfRequired()
    Return DirectCast(MyBase.GetEnumerator(), IEnumerator)
End Function

...

This way the collection is loaded dinamically from database (method LoadIfRequired) when I access it. It works well except on some LINQ to Objects querys (I think it happens only with OrderBy ones). I have a breakpoint on both GetEnumerator methods to know when they are called.

The current query doesn't stop on these methods:

    Dim colection As New clsColection(Of clsObjeto)

    Dim LINQQuery = From elem In colection Order By elem
    MsgBox(LINQQuery.Count)

The current query call stops on the first GetEnumerator:

    Dim colection As New clsColection(Of clsObjeto)

    Dim LINQQuery = From elem In colection Select elem Order By elem
    MsgBox(LINQQuery.Count)

What could be the problem?