filter challenge

Posts   
 
    
tvoss avatar
tvoss
User
Posts: 192
Joined: 07-Dec-2003
# Posted on: 10-Jul-2007 01:38:30   

Using getmulti with relations is there a better way to do this filtering?

I have a samplerequestcollection which has 1 to many relation with sampleresult entities.

One samplerequest can have sampleresults from many laboratories.

Only when all sampleresults are, sampleresult.complete, do I want a samplerequest to show up in the evaluation list.

The problem is how to do this with one filter or getmulti or something fast as I have to do this a lot.

The only way I've found so far is: find all samplerequestentities with some sampleresults complete as the goodcollection find all samplerequests with some sampleresults not done as the badcollection and then for each badrequest remove it from the list of goodrequests, to get the net list.

Here is the code: Dim relations As New RelationCollection relations.Add(SamplerequestEntity.Relations.SampleresultEntityUsingSampleid) Dim bSort As ISortExpression = New SortExpression bSort.Add(New SortClause(SamplerequestFields.Batchid, SortOperator.Ascending)) Dim gFilter As IPredicateExpression = New PredicateExpression gFilter.Add(SampleresultFields.Complete = True) gFilter.AddWithAnd(SamplerequestFields.Batched = True) Dim goodSamps As New SamplerequestCollection goodSamps.GetMulti(gFilter, 0, bSort, relations) Dim bFilter As IPredicateExpression = New PredicateExpression bFilter.Add(SampleresultFields.Complete = False) bFilter.AddWithAnd(SamplerequestFields.Batched = True) Dim badSamps As New SamplerequestCollection badSamps.GetMulti(bFilter, 0, bSort, relations) For Each sample As SamplerequestEntity In badSamps Try goodSamps.Remove(sample) Catch ex As Exception End Try Next

Can someone see a more optimum way to get the samplerequestcollection? TIA

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 10-Jul-2007 03:49:52   

I think you can make it in a one-trip call if you use **FieldCompareSetPredicate **and not-in clause on it. If you need assistance in that, consult the help, the forums, and of course you can let us know simple_smile

David Elizondo | LLBLGen Support Team
tvoss avatar
tvoss
User
Posts: 192
Joined: 07-Dec-2003
# Posted on: 10-Jul-2007 21:22:02   

Yes, FieldCompareSetPredicate makes sense and works, but I do need the not-in clause and cannot find it in forum or help since I get every in and not found.

This code works: Dim relations As New RelationCollection relations.Add(SamplerequestEntity.Relations.SampleresultEntityUsingSampleid) Dim bSort As ISortExpression = New SortExpression bSort.Add(New SortClause(SamplerequestFields.Batchid, SortOperator.Ascending)) Dim gFilter As IPredicateExpression = New PredicateExpression gFilter.Add(SamplerequestFields.Batched = True) gFilter.AddWithAnd(SamplerequestFields.Evaluated = False) Dim g1Filter As IPredicateExpression = New PredicateExpression g1Filter.Add(SampleresultFields.Complete = False) g1Filter.AddWithAnd(SampleresultFields.Manual = False) gFilter.Add(New FieldCompareSetPredicate(SamplerequestFields.Id, SampleresultFields.Sampleid, SetOperator.in, g1Filter)) Dim goodSamps As New SamplerequestCollection goodSamps.GetMulti(gFilter, 0, bSort, relations)

How would I add the not-in clause? Thanks,

tvoss avatar
tvoss
User
Posts: 192
Joined: 07-Dec-2003
# Posted on: 10-Jul-2007 21:38:08   

I just saw the overload with the negate at the end.

That seems to work. Is that what you were referring to? (negate = true) is the not-in clause? Thanks,

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 10-Jul-2007 21:44:45   

Yes.. that's what I'm talking about simple_smile congratulations.

David Elizondo | LLBLGen Support Team