newb question about proper usage of entity

Posts   
 
    
dma550
User
Posts: 20
Joined: 11-Feb-2006
# Posted on: 13-Feb-2006 20:56:36   

Hi all

First post here... first off, this is an amazing product and a great value. I am currently testing the demo version to see how it fits in with my development, and I must say, I am both amazed and feeling over my head at the same time!

I apologize if this has been asked in other forms, but I am new to the lingo as well, so I could not easily find an answer.

Now, on to my question: I have an entity defined, which has related entities under it. it looks like this: Organization |-> Subscription | ---- Org (bill to) | ---- Org (DeliverTo)

It's working beautifully. If I load the organization, I see the related 10 or so subscriptions owned by them.

My question: I need to show a small grid of some combined elements from the parent and the child entities... for instance: "Org(deliverto).Name, Subscriptions.count, Subscriptions.status, Org(deliverto).Address", etc.

In my current non-llblgen approach, I have a view that represents the combined sets for the grid, and upon selection of the grid, I load the elements to the other related parts on the fly (very messy, and hand-coded).

Ideally, I would like to be able to use llblgen to do this, loading the organiztion entity, and have edits made at the various entities and subentities, and then do a .save(true) and have it all save elegantly. I am most questioning how I would make a flattened result set out of part of this to show in the grid.

Any help is appreciated, thanks for listening simple_smile

Can this be done, and if so, some pointers would be great.

dma550
User
Posts: 20
Joined: 11-Feb-2006
# Posted on: 13-Feb-2006 22:18:36   

OK, I may have found it, please someone let me know if this is the right way to go about it.

I went in and added them as "fields mapped on database fields". I defined the few that would be necessary for the view. Seemed to work fine.

Posts: 40
Joined: 01-Sep-2005
# Posted on: 14-Feb-2006 00:34:54   

Have a look at Prefetch paths... Load the Organisation and set the Pretchfetch paths to load all the associated entities.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 14-Feb-2006 07:32:29   

I went in and added them as "fields mapped on database fields". I defined the few that would be necessary for the view. Seemed to work fine.

I think you mean "Fields on related fields", right? Just take care of 2 points: 1- These fields won't be loaded with data unless you use PrefetchPaths as Paul has suggested. 2- These fields will be Read-Only, so you may use them for viewing in your datagrid, but for the editable controls use the corresponding fields from the related Entities

dma550
User
Posts: 20
Joined: 11-Feb-2006
# Posted on: 14-Feb-2006 15:46:18   

Thanks Guys! Good community here, much appreciated!

"I think you mean "Fields on related fields", right?"

Yes, sorry, that is where I placed them.

A few things though... I updated them this way:

c.SubBillTo(0).Name="test elementary school"
c.Save(true)

.Name on Subscription is a "field mapped on related field", it does not exist on the subscription entity. It updated properly:

exec sp_executesql N'UPDATE [dbo].[organization] SET [name]=@Name WHERE ( [dbo].[organization].[Org_ID] = @OrgId1)', N'@Name varchar(64),@OrgId1 int', @Name = 'test elementary school', @OrgId1 = 800003

it does work, is this something I can rely on?

And also, I did not have to do anything with prefetch, it grabbed the data itself by doing a subsequent query. Is the point of the prefetch effeciency versus the seperate query?

Thanks again!

-DMA

dma550
User
Posts: 20
Joined: 11-Feb-2006
# Posted on: 14-Feb-2006 17:19:02   

ok, I see what's happening now.

As I am using the self servicing provider, I am getting lazy loading helping me out.

When using the code code behind it works great. When I bind it to a grid it's doing 25 extra queries per line to get the data. Yikes.

So, I am looking deeper into prefetch. I am not entirely sure what benefit prefetch will offer, will it gather the data via a join or run fewer queries when the grid loads the data?

I know I am probably murdering this, but this is what I am trying to do:


        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

I am trying to load the organizationentity numbered 10400002. This will be displayed, the user may edit the master organization entity.

The grid is bound to the subentity "subbillto" of c. This is a list of all subscriptions paid for by the parent org C. Running it without prefetch ends up in lots of extra queries when binding a grid to c.SubBillTo.

Can someone comment on how I could effectively use prefetch in this case, and what my gains would be (ie only 1 query per subscription with a join?)? Ideally, the grid should be able to show some fields from the c.SubBillTo->relatedOrg (state, zip, address).

Thanks for putting up with me!

Thanks!

dma550
User
Posts: 20
Joined: 11-Feb-2006
# Posted on: 14-Feb-2006 22:20:29   

ok, this works, but I've lost my relationships from the entity.


        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

However, I would prefer to keep the arrangement as per the previous message, using the entity. Can this be done? Please someone lol I am dying here wink

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

how I would make a flattened result set out of part of this to show in the grid.

Either by using a "Fields on related Fields" or by using TypedLists, TypedViews and Dynamic Lists.


c.SubBillTo(0).Name="test elementary school"
c.Save(true)

.Name on Subscription is a "field mapped on related field", it does not exist on the subscription entity. It updated properly:

I suppose SybBillTO(0) is an Org Entity, then Name is not a "Field on related Field" it is a field defined in Org Table, that's why it is updated correctly.

or else I need you to re-explain your objects structure(shown below), as I seem to be confused with it

Organization |-> Subscription | ---- Org (bill to) | ---- Org (DeliverTo)

Thanks and Good Luck

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

Thanks Walaa

Actually, c = organization, subBillTo is a sub-entity of organization related by FK. Name is a mapped "field on related field". SUbBillTo(0) is the first row in the subscription entity.

So me doing what I did is in essence traversing the Main organization, then locating all subscriptions that are billed to that organization, then locaing the child organization that is linked by the subscription.

I think why it's working is all about lazy loading. Thanks again!

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 15-Feb-2006 15:45:20   

please check my reply to you on the other thread: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=5402