Collection using relations

Posts   
 
    
G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 16-Aug-2005 15:33:33   

Hi,

I have to following problem:

I have a PART. This PART is a part of a MODEL. This MODEL can have several PARTS. Therefore I have a PARTMODEL table.

A MACHINE is of some kind of MODEL. So in the table MACHINE i have the MODEL_OBJ_NO In the table PARTMODEL I have the PART_OBJ_NO and the MODEL_OBJ_NO.

What I need is all the parts in table PART that a MACHINE has.

So Machine - Model 1:1 Model - Part m:m

All I have is the Machine_Obj_no and I need a collection of PARTentities. How do I get this? I need to define the relations somehow and a filter on the machineObjNo. But I don't know how to do this? I can't find a good example in the documentation that looks like my situation. Plz. help me!

Gr.,

Robin

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 17-Aug-2005 12:04:02   

G.I. wrote:

Hi,

I have to following problem:

I have a PART. This PART is a part of a MODEL. This MODEL can have several PARTS. Therefore I have a PARTMODEL table.

A MACHINE is of some kind of MODEL. So in the table MACHINE i have the MODEL_OBJ_NO In the table PARTMODEL I have the PART_OBJ_NO and the MODEL_OBJ_NO.

What I need is all the parts in table PART that a MACHINE has.

So Machine - Model 1:1 Model - Part m:m

All I have is the Machine_Obj_no and I need a collection of PARTentities. How do I get this? I need to define the relations somehow and a filter on the machineObjNo. But I don't know how to do this? I can't find a good example in the documentation that looks like my situation. Plz. help me!

Rule of thumb, as described in the Northwind example's customer filtered onproduct code: start with the entity you want to retrieve and then work down to the entity you want to filter on. so, using this, the relations to follow are: Part - PartModel - Model - Machine And you have to specify a fieldcomparevalue predicate which filters on Machine.Machine_Obj_No with the given value.

So, the relations collection will become: (I use selfservicing here, not sure what you're using). It can be the names of the relations are a bit different in your situation, but you'll get the idea


RelationCollection relations = new RelationCollection();
relations.Add(PartEntity.Relations.PartModelEntityUsingPartObjNo);
relations.Add(PartModelEntity.Relations.ModelEntityUsingModelObjNo);
relations.Add(ModelEntity.Relations.MachineEntityUsingMachineObjNo);
// filter
PredicateExpression filter = new PredicateExpression();
filter.Add(PredicateFactory.CompareValue(MachineFieldIndex.MachineObjNo, ComparisonOperator.Equal, _machineObjNo));
// fetch
PartCollection parts = new PartCollection();
parts.GetMulti(filter, relations);

Frans Bouma | Lead developer LLBLGen Pro
G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 18-Aug-2005 09:14:43   

SIGH ... I don't know how you do it, but you do the same thing I thought I did myself and now it works. I wish I remembered what I did yesterday, but thank you very much simple_smile

The thing that I like about this forum is that you often get SourceCode examples from people trying to help, and not just some message how you should do it. This is sooo much clearer this way.

Thank you very much!

Gr.,

G.I.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 18-Aug-2005 10:51:48   

smile Thanks G.I. simple_smile

Frans Bouma | Lead developer LLBLGen Pro