EntityCollection - Find by PK

Posts   
 
    
mshe
User
Posts: 167
Joined: 02-Feb-2006
# Posted on: 06-Nov-2006 08:54:54   

Hi all,

Is there a possiblity of adding a "Find By PK" function for an EntityCollection? Or Perhaps the EntityCollection.Item property could be indexed by PK as well?

I know there is a "FindMatches" function already, but I think it would be cleaner if I could just pass in the PK and get the object directly?

Thanks!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 06-Nov-2006 09:52:12   

mshe wrote:

Hi all,

Is there a possiblity of adding a "Find By PK" function for an EntityCollection? Or Perhaps the EntityCollection.Item property could be indexed by PK as well?

What if the PK contains 3 fields?

I know there is a "FindMatches" function already, but I think it would be cleaner if I could just pass in the PK and get the object directly? Thanks!

the problem is that in adapter code, this is difficult, because the EntityCollection is a generic collection class, and therefore FindByPk will then become a complex method which wont be that simpler than setting up a simple predicate with FindMatches.

Frans Bouma | Lead developer LLBLGen Pro
mshe
User
Posts: 167
Joined: 02-Feb-2006
# Posted on: 06-Nov-2006 11:13:41   

Otis wrote:

mshe wrote:

Hi all,

Is there a possiblity of adding a "Find By PK" function for an EntityCollection? Or Perhaps the EntityCollection.Item property could be indexed by PK as well?

What if the PK contains 3 fields?

the problem is that in adapter code, this is difficult, because the EntityCollection is a generic collection class, and therefore FindByPk will then become a complex method which wont be that simpler than setting up a simple predicate with FindMatches.

How about an array parameter field like:

EntityCollection.Find(new object() {PK1, PK2, PK3, PK4, etc})?

OR

EntityCollection.Find(new object() {new SomeLLBLGenObject("PK1", value), new SomeLLBLGenObject("PK2", value)})

Just an idea - I think it's just personal preference... also because I believe the Adapter class has a "FetchUnique" function. I just find the FindMatches function a bit unintuitive to use to fetch unique rows (i.e. some of my entity collections are hashtable like - I use them to store parameters for an associated Entity - like MyEntity.ParameterCollection).

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 06-Nov-2006 11:31:39   

FindMatches is a routine which is available to you but is meant to be used by the EntityView2 class. If you want an intuitive way to access entities matching a given predicate, simply create an Entityview2 on the entitycollection and pass in the filter to the constructor. You can then iterate over the entityview to obtain the matching entities simple_smile

Frans Bouma | Lead developer LLBLGen Pro