Is there a Find method in the Entity collections?

Posts   
 
    
Aglaia avatar
Aglaia
LLBLGen Pro Team
Posts: 535
Joined: 07-Sep-2003
# Posted on: 21-Aug-2007 13:20:58   

Question: I want to look up an entity in a collection with read entities. Is there a Find method in the Entity collections?

Solution: You can find entities easily with in-memory filtering on an entitycollection. Take for example the following code, which finds the CustomerEntity with the PK "CHOPS" in the customer collection. This works for both Adapter and SelfServicing. It will use the DefaultView object for this.


// C#
CustomerCollection customers = new CustomerCollection();
// get all customers
customers.GetMulti(null);
IEntityView view = customers.DefaultView;
// filter view
view.Filter = (CustomerFields.CustomerId == "CHOPS");
// get a reference to the entity to find:
CustomerEntity toFind = view[0];

 VB.NET
Dim customers As New CustomerCollection()
' get all customers
customers.GetMulti(Nothing)
Dim view As IEntityView = customers.DefaultView
' filter view
view.Filter = New FieldCompareValuePredicate(CustomerFields.CustomerId, _
ComparisonOperator.Equals, "CHOPS")
' get a reference to the entity to find:
CustomerEntity toFind = view(0)