Example of prefetch with entity please (self servicing)

Posts   
 
    
dma550
User
Posts: 20
Joined: 11-Feb-2006
# Posted on: 15-Feb-2006 01:22:46   

Hi all

This is a evo/devo - lution of a previous post:

http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=5395

I am wondering, is it possible to use prefetch paths with an entity rather than using a collection? I cannot get it working, asper the post above. I am using self-servicing.

I'm hoping to do something like this:


    Dim PrefetchPath As IPrefetchPath = New PrefetchPath(CType(EntityType.OrganizationEntity, Integer))
        PrefetchPath.Add(OrganizationEntity.PrefetchPathSubBillTo)
        Dim c As New OrganizationEntity(10400002, PrefetchPath)
        Me.SubscriptionEntityBindingSource.DataSource = c.SubBillTo

as I want the child entities under the organization to be loaded. Can anyone either comment on this or the above post before I jump out of a window?

Thanks!

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 15-Feb-2006 04:22:01   

You need to add a prefetch path for each entity property that you link to that is related to organization. Can you post what you are trying to display with your grid. In your other post you mention that you have fields from related entities. So if you are displaying all of these values in a grid then each of those related entites need to have their prefetch path added. Post some more information and we'll get it working.

dma550
User
Posts: 20
Joined: 11-Feb-2006
# Posted on: 15-Feb-2006 05:59:37   

Thanks for your post.

As I mentioned in the other thread, I got this working, but note it uses a collection.

       Dim csub As New SubscriptionCollection()
        Dim prefetchPath As IPrefetchPath = New PrefetchPath(CType(EntityType.SubscriptionEntity, Integer))
        prefetchPath.Add(SubscriptionEntity.PrefetchPathOrgDeliverTo)
        Dim filter As IPredicateExpression = New PredicateExpression()
        filter.Add(PredicateFactory.CompareValue(smdbdata.SubscriptionFieldIndex.BillToOrgId, ComparisonOperator.Equal, 10400002))
        csub.GetMulti(filter, prefetchPath)
        Me.SubscriptionEntityBindingSource.DataSource = csub

When the subscription record is shown on the grid, I need to relate the related addressee information from the related organization. For testing purposes, I am choosing only address to make it simple. Using the above code, it prefetches properly, and I see only two queries, one for the initial subscription list, and the other for the address for each (it uses an in clause).

Ideally, I want to use the entity itself:

Organization -> Subscription -> BillToOrganization | -> DeliverToOrganization

So, I start with an open on the organization entity. I would then try to bind the grid to the SubBillTo relation.

Can you post what you are trying to display with your grid. In your other post you mention that you have fields from related entities. So if you are displaying all of these values in a grid then each of those related entites need to have their prefetch path added. Post some more information and we'll get it working.

OK, so yes, one field from the organization for now - this is built in the designer as a field from related entity. As the collection code above works, can you help me adapt it to the entity itself? On the other post I have my attempt at doing it, it's not working rage

Lastly, I was concerned with the use of "in" for prefetch, as it supplied hard coded values (in params). Isn't there a limit to the length of the in clause or the overall size of the SQL batch? What would happen if I tried to prefetch city/state/zip for 3000 related rows (though I would not in all practicality)?

Thanks for working with me. My eval is going well, I will need to make my customers comfortable with this shift from a simple template built SP based template to your tool.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 15-Feb-2006 07:09:40   

I seem to be a little confused with your object structure but I'm gussing that this is what you are looking for:

Dim PrefetchPath As IPrefetchPath = New PrefetchPath(CType(EntityType.OrganizationEntity, Integer))
        PrefetchPath.Add(OrganizationEntity.PrefetchPathSubBillTo).SubPath.Add(SubscriptionEntity.PrefetchPathOrgDeliverTo)
        Dim c As New OrganizationEntity(10400002, PrefetchPath)
        Me.SubscriptionEntityBindingSource.DataSource = c.SubBillTo

Take note of the SubPath part.

dma550
User
Posts: 20
Joined: 11-Feb-2006
# Posted on: 15-Feb-2006 16:47:02   

simple_smile simple_smile simple_smile

Thanks Walaa that did it.

I need to immerse myself deeply in the docs now, now that I know I can use this framework.

One other thing that it does nicely is that for small prefetches, IE 10 rows, it uses a PK based "in clause". For a large prefetch, (I tried one with 2K rows) it did a nice correlated subquery.

Kudos, I've found my new ORM!

-DMA