PrefetchPath2 Not Working

Posts   
 
    
Posts: 21
Joined: 07-Jul-2008
# Posted on: 22-Apr-2009 22:46:25   

My Code

EntityCollection<FslClientEntity> DataSource = new EntityCollection<FslClientEntity>();

PrefetchPath2 Join = new PrefetchPath2(((int)EntityType.FslClientEntity));

Join.Add(FslClientEntity.PrefetchPathHotSiteCollectionViaFslClientHotSite);

using (DataAccessAdapter adapter = new DataAccessAdapter())
{
    adapter.FetchEntityCollection(DataSource, Filter, PageSize, Sort, Join, CurrentPage, PageSize);
}

return DataSource;

Generated Query Without Join/Relationship

SELECT
    DISTINCT
    TOP 10
    [FSL_Client].[IdClient], 
    [FSL_Client].[Nome], 
    [FSL_Client].[Sobrenome], 
    [FSL_Client].[Email], 
    [FSL_Client].[Senha], 
    [FSL_Client].[TipoPessoa], 
    [FSL_Client].[IdEstado], 
    [FSL_Client].[Cidade], 
    [FSL_Client].[Endereco], 
    [FSL_Client].[Telefone], 
    [FSL_Client].[Celular], 
    [FSL_Client].[IsNewsletter],
    [FSL_Client].[DataCadastro]
FROM
    [FSL_Client]

I really don't know why Not Working. Please Help!!

Windows XP Pro SP3 - IIS 5.1 LLBLGen 2.6 Final Registered Adapter Mode Sql Server 2005 .Net Framework 3.5

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 23-Apr-2009 05:48:50   

Using the prefetchPath wont generate a join. If you look closely at the full generated sql, you will see two queries: one for the main collection and one for the prefetchPath. (more info...)

David Elizondo | LLBLGen Support Team
Posts: 21
Joined: 07-Jul-2008
# Posted on: 23-Apr-2009 15:25:01   

daelmo wrote:

Using the prefetchPath wont generate a join. If you look closely at the full generated sql, you will see two queries: one for the main collection and one for the prefetchPath. (more info...)

Okay...

See this:

FslClienteEntity client = new FslClienteEntity();
txtNome.Text = client.Nome;
foreach (HotSiteEntity item in client.HotSiteCollectionViaFslClienteHotSite)
{
    lstHotSites.Items.Add(new ListItem(item.Titulo, item.IdHotSite.ToString()));
}
//but 'client.HotSiteCollectionViaFslClienteHotSite' is null
//obviously have records in database for this test

How i 'Prefetch' client.HotSiteCollectionViaFslClienteHotSite ??

Prefetch, Correctly? i can't see error in my code..

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 23-Apr-2009 16:26:41   

Using SQL profiler can you see the multiple SQL statements being generated...? and does it work if you leave out all of the paging, sorting, filtering etc - so just the simplest case possible...?


using (DataAccessAdapter adapter = new DataAccessAdapter())
{
    adapter.FetchEntityCollection(DataSource, null, null, null, Join,null, null);
}

Matt

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 23-Apr-2009 16:30:59   

Also see the documentation about prefetch paths and paging here

Matt

Posts: 21
Joined: 07-Jul-2008
# Posted on: 23-Apr-2009 16:57:42   

MTrinder wrote:

Also see the documentation about prefetch paths and paging here

Matt

Matt I only need to filter FslClientEntity. See my tables.

Attachments
Filename File size Added on Approval
LLGLGen.JPG 30,252 23-Apr-2009 16:58.00 Approved
MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 23-Apr-2009 21:05:31   

If you only need to fetch FSLClientEntity, without any related entities, why do you need a pre-fetch path...?

Matt

Posts: 21
Joined: 07-Jul-2008
# Posted on: 23-Apr-2009 22:24:27   

MTrinder wrote:

If you only need to fetch FSLClientEntity, without any related entities, why do you need a pre-fetch path...?

Matt

Table FSL_Cliente_HotSite Describe to me the relations.

Examples: - Fill Grid with FSLClientEntity that are member of HotSite Active - Fill Grid with FSLClientEntity in HotSite #123

Understand Me?

(Sorry.. Native Language: Portuguese..)


Solved using SQL View:

SELECT
    dbo.FSL_Cliente.*,
    dbo.HotSite.IdHotSite,
    dbo.HotSite.Titulo
FROM
    dbo.FSL_Cliente
    INNER JOIN dbo.FSL_Cliente_HotSite
    ON dbo.FSL_Cliente.IdCliente = dbo.FSL_Cliente_HotSite.IdCliente
    INNER JOIN dbo.HotSite
    ON dbo.FSL_Cliente_HotSite.IdHotSite = dbo.HotSite.IdHotSite

And now my control are enabled with views (http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=15633)

Solved with other Solution... Will continue this topic? Staff..

Thanks LLBLGen Team!

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 23-Apr-2009 22:31:42   

You need to use Relations, which are the LLBLGen equivalent of JOINs. PreFetch paths are for fetching an entity with its related entites, Relations are for fetching a single entity (or collection of entites) but using a query against another table.

Matt

Posts: 21
Joined: 07-Jul-2008
# Posted on: 23-Apr-2009 22:37:08   

MTrinder wrote:

You need to use Relations, which are the LLBLGen equivalent of JOINs. PreFetch paths are for fetching an entity with its related entites, Relations are for fetching a single entity (or collection of entites) but using a query against another table.

Matt

Thanks Matt.

Closed.