Fetching an Entity filtered by foreign key...

Posts   
 
    
JayMan
User
Posts: 9
Joined: 02-May-2006
# Posted on: 31-May-2006 15:29:56   

Hi, I wonder if anyone could help me out on how to use FetchNewEntity() to get an entity based on a foreign key. Thanks in advance, Jayman

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 31-May-2006 16:21:35   

If you mean using a related entity that holds a FK to this entity's PK then you can use the FetchNewEntity() as follows:

DataAccessAdapter adapter = new DataAccessAdapter(true);
OrderEntity order = new OrderEntity(10254);
adapter.FetchEntity(order);
order.Customer = (CustomerEntity)adapter.FetchNewEntity(new CustomerEntityFactory(), 
    order.GetRelationInfoCustomer());
adapter.CloseConnection();

Else if you mean to fetch an entity using a FK column in its table, unless this FK is unique, there might be more than one entity (row that holds the same FK value), in this case it would better to fetch an EntityCollection with the appropriate filter.

Please refer to the LLBLGen Pro manual: "Using the generated code -> Adapter/SelfServicing -> Using the entity classes" "Using the generated code -> Adapter/SelfServicing -> Using the entity collection classes"

For using filters please refer to the LLBLGen Pro manual: "Using the generated code -> Adapter/SelfServicing -> Filtering and sorting" Also check the samples in the "Best practises - How do I ... ?" section look for the questions that starts with "write a filter which does..."