Find Entity in EntityCollection using PK

Posts   
 
    
IT
User
Posts: 37
Joined: 02-Dec-2003
# Posted on: 19-Dec-2003 14:53:50   

How do i find an entity in a Entitycollection based on the PrimaryKey (PK)

This will work - but is it the preferred way to do it ? sunglasses

Dim FunctionGrp As FunctionGrpEntity
                Dim fg As New FunctionGrpEntity(MyPK)
                Dim fgindex As Integer = FunctionGrpElements.IndexOf(fg)

                If fgindex > -1 Then
                    objFunctionGrp = _department.FunctionGrpElements(fgindex)
                Else
                    'Not available
                End If

... IT

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 19-Dec-2003 14:57:54   

This works and is the prefered way to do it. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
IT
User
Posts: 37
Joined: 02-Dec-2003
# Posted on: 19-Dec-2003 15:03:50   

Thanks smile

pat
User
Posts: 215
Joined: 02-Mar-2006
# Posted on: 21-Nov-2008 10:52:07   

Hi,

is this still the best and fastest way to do it on big collections?

Thanks a lot, Patrick

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 21-Nov-2008 11:00:18   

You may loop once, store the entities per PK into a hashtable/ dictionary, and then for all subsequential lookups use that hashtable/dictionary

pat
User
Posts: 215
Joined: 02-Mar-2006
# Posted on: 06-Feb-2009 21:07:56   

Walaa wrote:

You may loop once, store the entities per PK into a hashtable/ dictionary, and then for all subsequential lookups use that hashtable/dictionary

Maybe one day this get's integrated into LLBLGen so that fast lookup's come out of the box simple_smile http://www.codeplex.com/i4o

Just a suggestion sunglasses Thanks, Patrick

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 07-Feb-2009 04:23:31   

As a matter of fact, there's a conversation about that: http://llblgen.com/TinyForum/Messages.aspx?ThreadID=11939

David Elizondo | LLBLGen Support Team