Filter a child entity collection question

Posts   
 
    
slacroix
User
Posts: 4
Joined: 19-Jan-2005
# Posted on: 26-Jan-2005 22:10:32   

I may be going about this the wrong way...

I have a table with parts. A part has a field for active (bit). Parts are related to product lines with a cross reference table..

Currently I have a combo box with the product line and a listbox with the parts.

I am trying to only display the parts that are: a)related to the selected product line. b) active.

I've looked through the docs and others posts. I found a few related posts but I cant seem to get it right.

I've tried a few things similar to this In selectedIndexChanged event handler for the product line combo box:


listParts.DisplayMember = "PartNo";
IPredicateExpression aFilter = new PredicateExpression();
aFilter.Add(PredicateFactory.CompareValue(PartFieldIndex.IsActive, ComparisonOperator.Equal, true));

selectedProdLine.Part.GetMulti(aFilter);
listParts.DataSource = selectedProdLine.Part;

Am I on the right track? or do I have to create a new PartCollection. Setup the relationships and filter based on productline and a filter based on active? Is there anything wrong with doing this in the Index changed event handler for the combo box? Will my list change like I want it to?

what about selectedProdLine.GetMultiPart()....it doesnt seem to accept a filter?

btw: I am fairly new to .net. I am truly enjoying the product. I found it looking for some examples of complex datatable relation traversals (thank that random guy who lists your product in his blog). I have convinced the company to purchase and a I told a few friends about you guys. Thanks for the effort.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 27-Jan-2005 09:53:41   

slacroix wrote:

I may be going about this the wrong way...

I have a table with parts. A part has a field for active (bit). Parts are related to product lines with a cross reference table..

Currently I have a combo box with the product line and a listbox with the parts.

I am trying to only display the parts that are: a)related to the selected product line. b) active.

I've looked through the docs and others posts. I found a few related posts but I cant seem to get it right.

I've tried a few things similar to this In selectedIndexChanged event handler for the product line combo box:


listParts.DisplayMember = "PartNo";
IPredicateExpression aFilter = new PredicateExpression();
aFilter.Add(PredicateFactory.CompareValue(PartFieldIndex.IsActive, ComparisonOperator.Equal, true));

selectedProdLine.Part.GetMulti(aFilter);
listParts.DataSource = selectedProdLine.Part;

Am I on the right track? or do I have to create a new PartCollection. Setup the relationships and filter based on productline and a filter based on active? Is there anything wrong with doing this in the Index changed event handler for the combo box? Will my list change like I want it to?

You should use: selectedProdLine.GetMultiPart(true, new PartEntityFactory(), aFilter);

This is the 3rd overload of GetMultiPart, which does accept a filter. This filter is applied with the FK filter for parts. True is specified to force a fetch, as the lazy loading code already fetched data. simple_smile

what about selectedProdLine.GetMultiPart()....it doesnt seem to accept a filter?

It should be there, you should have 4 overloads. Unless prodline - part is an m:n relation. Is that the case?

btw: I am fairly new to .net. I am truly enjoying the product. I found it looking for some examples of complex datatable relation traversals (thank that random guy who lists your product in his blog). I have convinced the company to purchase and a I told a few friends about you guys. Thanks for the effort.

smile

Frans Bouma | Lead developer LLBLGen Pro
slacroix
User
Posts: 4
Joined: 19-Jan-2005
# Posted on: 27-Jan-2005 15:45:39   

what about selectedProdLine.GetMultiPart()....it doesnt seem to accept a filter?

It should be there, you should have 4 overloads. Unless prodline - part is an m:n relation. Is that the case?

Sorry, I should have been clear. It is the case.

My layout is like so:

Part

PartNo (pk) PartDesc ...

ProdLine

ProdLineId (pk) ProdLineDesc ...

PartToProdLine

PartNo (comppk) ProdLineId (comppk)

What is the best way to handle this in this situation?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 27-Jan-2005 18:36:50   

As m:n relations rely on an intermediate entity, you have to refetch the m:n collection by hand if you want additional filtering. GetMultiPart is building up the filter by hand for you, but doesn't accept an additional filter.

So the proper way to do this is to setup the filter by hand. Easiest way to do this is to open the ProdLineEntity.GetMultiPart() routine and grab the filter + relation creation code.

then add your line you already have (filter.Add(PredicateFactory.CompareValue(PartFieldIndex.IsActive, ComparisonOperator.Equal, true)); ) and call selectedProdLine.Part.GetMulti(filter, relations);

Frans Bouma | Lead developer LLBLGen Pro
slacroix
User
Posts: 4
Joined: 19-Jan-2005
# Posted on: 27-Jan-2005 22:08:48   

Thanks much. Minor changes to the code copied, added the other filter.....it works great.