Prefetching on DB

Posts   
 
    
Lain
User
Posts: 13
Joined: 19-Mar-2009
# Posted on: 28-May-2013 10:47:57   

Hi guys

I am using prefetch paths to pre-fetch entities from related tables. In our application I usually only need to fetch one column from the related table so it is pretty much a waste to fetch the entire entity.

I basically want to join 2 tables and project one column from the joined table in the primary table and I want to do this join on the database. When I use Prefetch paths LLBLGen generates a query for each table I'm referring and fetches the entities.

Here is a (real) SQL-Query I am trying to generate using LLBLGen:

select baac_id, baac_code, ascr_code from ba_account, as_currency where baac_currency1fk = ascr_id;

Where baac_id, baac_code and baac_currency1fk are columns in the table ba_account and baac_currency1fk is a foreign key to the table as_currency. ascr_id and ascr_code are columns of as_currency.

How could I generate a similar query using LLBLGen?

I'm using LLBLGen Pro Version 2.6

Thanks!

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 28-May-2013 21:15:46   

It depends on how you want the fetched records be presented.

  • Fetch fields from more thean one entity (joined) in a flat structure.
  • Fetch fields from more than one table in a Graph (hierarchy of entities).

P.S. you can instruct the prefetchPath to only fetch the fields you want. use the following overload, the last parameters defines which entities to fetch or to ignore. Please check the Reference Manual.

public virtual IPrefetchPathElement Add(
    IPrefetchPathElement elementToAdd,
    int maxAmountOfItemsToReturn,
    IPredicateExpression additionalFilter,
    IRelationCollection additionalFilterRelations,
    ISortExpression additionalSorter,
    ExcludeIncludeFieldsList excludedIncludedFields
)