Prefetching 3 nodes deep...

Posts   
 
    
JayMan
User
Posts: 9
Joined: 02-May-2006
# Posted on: 02-May-2006 14:15:27   

Hi, I am using a "Account" table that has a foreign key "AddressID" that links to the "Address" table which in turn has a "CountryID" that points to the "Country" table.

Q 1. How can I prefetch all 3 levels in one go? Q 2. How can I add a new "Account" record and populate all three tables?

Any help will be invaluable. Thanks in advance.

Jayman

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 02-May-2006 18:08:36   

Q 1. How can I prefetch all 3 levels in one go?

Use a PrefetchPath with subpath.

IPrefetchPath2 path = new PrefetchPath2((int)EntityType.AccountEntity);
path.Add(AccountEntity.PrefetchAddress).SubPath.Add(AddressEntity.PrefetchPathCountry);

Q 2. How can I add a new "Account" record and populate all three tables?

AccountEntity Account = new AccountEntity();
AddressEntity Address = new AddressEntity()
Address.field1 = ...
.
.
Address.Country = Country; // Country is created the same way
Account.field1 = ...
.
.
Account.Address = Address;
adapter.SaveEntity(Account);
JayMan
User
Posts: 9
Joined: 02-May-2006
# Posted on: 03-May-2006 05:13:59   

Thanks so very much Walaa. Really appreciate it. I'll give it a go.

bunzee
User
Posts: 84
Joined: 20-Mar-2007
# Posted on: 17-May-2007 21:28:43   

Hi,

I have something similar but somewhat different.

Let's say I have 4 tables: bill, claim, client, and employer with the following relationships: bill.claimID = claim.ID (thus m:1 relationship) claim.clientID = client.ID (thus m:1 relationship) claim.employerID = employer.ID (thus m:1 relationship)

Problem:

1) In the designer, I want to create bill-to-client or bill-to-employer relationship but I cannot. 2) Since I cannot do in the designer, I do it programmatically via: IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.BillEntity); prefetchPath.Add(BillEntity.PrefetchPathClaim); prefetchPath.Add(BillEntity.PrefetchPathClaim).SubPath.Add(ClaimEntity.PrefetchPathClient); prefetchPath.Add(BillEntity.PrefetchPathClaim).SubPath.Add(ClaimEntity.PrefetchPathEmployer);

and I got the error at line 3 where I subpath.add the client. The error said "The PrefetchPathElement you to tried to add is already added to this PrefethPath."

Basically what I want to do is in a formview, I will show the bill information, i also want to show the client name and the employer name.

Thank you,

BZ

bunzee
User
Posts: 84
Joined: 20-Mar-2007
# Posted on: 17-May-2007 22:27:31   

Ah,

I found the answer to the question #2, i.e. the programmatically prefetch multiple 3rd level nodes. The answer can be found here: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=3196&HighLight=1

The question #1 still remain. Any help would be greatly appreciated.

Thanks

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 18-May-2007 11:42:30   

Let's say I have 4 tables: bill, claim, client, and employer with the following relationships: bill.claimID = claim.ID (thus m:1 relationship) claim.clientID = client.ID (thus m:1 relationship) claim.employerID = employer.ID (thus m:1 relationship)

Problem:

1) In the designer, I want to create bill-to-client or bill-to-employer relationship but I cannot.

Custom m:n relations are created with 1:m-n:1 relations with an intermediate table that defines resolves the m:n relation.

And that's not the case with bill-claim-client (m:1-n:1) And neither with bill-claim-client-employer.

P.S. it's more convenient if you start a new thread, rather tha using an old thread(please, apply this next time, it's ok to continue your question in this thread)

bunzee
User
Posts: 84
Joined: 20-Mar-2007
# Posted on: 25-May-2007 02:01:51   

Walaa,

Thank you. I will make sure that next time I will create a new thread.

About my question #1 (In the designer, I want to create bill-to-client or bill-to-employer relationship but I cannot), I don't quite understand your answer.

I am aware that m:n relationship needs an intermediate table. In my case bill-claim-client or bill-claim-employer is not m:n but rather m:1 but with the complication of m:1-n:1. Are you saying that this is not possible to do in LLBLGenPro Designer?

Thank you very much,

BZ

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 29-May-2007 08:22:05   

Are you saying that this is not possible to do in LLBLGenPro Designer?

I'm afraid, yes....it's n ot possible.

If you want to fetch employers based on bill, you have to specify relations. You can create utility methods to do so, but there won't be properties on the entities which support this like with m:n relations.

What you want comes down to define a relation between any two entities and define it as a m:n relation and llblgen pro under the hood generates code which joins all these entities together. That's not supported. You should write out these few lines of code to fetch the related entities.

In LLBLGen Pro, every entity gets properties for directly related entities based on m:1/1:1/1:n and m:n relations. Entities which are indirectly related, i.e. via another entity and not in an m:n form, are reachable via that other entity though won't be available via a property, as they're already available via that related entity. It would mean that you could read any entity by just holding a bill entity, which is not a right thing to have.

Similar to why OrderDetails doesn't have a relation with Customer. It has a relation with Order. To reach the customer, you've to navigate upwards from order details to order and then to customer, simply because customer and orderdetails have no direct relation, they're reachable in the graph, but only indirectly. Same with his graph.