Prefetch path and generated query?

Posts   
 
    
llblPowa
User
Posts: 41
Joined: 19-Nov-2006
# Posted on: 04-Dec-2006 22:54:33   

v2.0.50727

Hello,

I am having the following tables :

Abonne can have (0 or many) Reglement.

In LLBL designer, relations exist.

when I am doing the following code :


IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.AbonneEntity);
            prefetchPath.Add(AbonneEntity.PrefetchPathReglement);

            AbonneEntity abonne = new AbonneEntity("AA003063");

            DataAccessAdapter adapter = new DataAccessAdapter();
            adapter.FetchEntity(abonne, prefetchPath); ;

2 Queries are generated (in Output windows as well as using the SQL profiler) :

1) select ... from Abonne where pk="AA003063" 2) select ... from Reglement where pk="AA003063"

(Hopefully, Abonne.Reglements is well filled)

May be I am wrong, but shouldn't I have only ONE query generated ? Something like select * from abonne, reglement where abonne.abonneID = reglement.abonneID and pk="AA003063"

Cheers,

LLblPowa

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 05-Dec-2006 06:06:10   

May be I am wrong, but shouldn't I have only ONE query generated ? Something like select * from abonne, reglement where abonne.abonneID = reglement.abonneID and pk="AA003063"

Nope, that one query will return no results if there are no Reglement entities related to the Abonne Entity.

That's why we fetch all (in case of a collection) the available Abonne entities and then we fetch all their related Reglement entities.

Since the goal of PrefetchPaths is to fetch the main entities then to fetch their related entities, not to filter out entities.

If you want to have a one filtering query, you should use a Predicates and Relations to formulate that query.

llblPowa
User
Posts: 41
Joined: 19-Nov-2006
# Posted on: 05-Dec-2006 11:16:31   

OK, so obvious :-)

Thanks Walaa.