Fetching a single entity - Can I avoid using a collection?

Posts   
 
    
Posts: 254
Joined: 16-Nov-2006
# Posted on: 10-Mar-2007 22:28:31   

Guys,

I'm trying to retrieve an entity using a filter however all the code in the documentation seems to show how to do this for a collection using the GetMulti method however I can't see how to do this for a single entity.

Other posts such as this http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=8975&HighLight=1 seem to mention using a collection is the only way if the column your searching on isn't a Primary Key or Unique Constraint.

If this is only possible through the collection couldn't the framework provide a method on the entity to perform the look up based on a predicate filter? I'm sure I'm missing this as this support must be there just can't find out where.

Many other fields on entities are usually indexed but aren't primary keys or unique constraints.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 11-Mar-2007 01:05:38   

Matt,

The thing is that if your search isn't based on a PK or a UC, the unique resulset entity isn't guarantee. So the search filter should be performed in a GetMulti (for SelfServicing) of a EntityCollection.

If this is only possible through the collection couldn't the framework provide a method on the entity to perform the look up based on a predicate filter?

But, what if the look-up return more than one result? which the search will select? frowning

I think the reference thread you posted is OK in that way.

David Elizondo | LLBLGen Support Team
Posts: 254
Joined: 16-Nov-2006
# Posted on: 11-Mar-2007 09:17:50   

Sure but there are always some columns of an entity for which UCs or PKs don't exist and which you know only one result will be returned.

In some cases perhaps you haven't the luxury of altering the schema too.

The code could simply throw an exception if more than one record was found

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 11-Mar-2007 18:30:12   

Sure but there are always some columns of an entity for which UCs or PKs don't exist and which you know only one result will be returned.

Well, however the framework don't have to worry, IMHO, of these exceptions (uniques that don't seems to be), and the code of retrieve that from a collection is pretty simple.

In some cases perhaps you haven't the luxury of altering the schema too.

But the framework is extensible simple_smile . You can do that method if you want, extending your EntityClass or modifying the template.

David Elizondo | LLBLGen Support Team