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);