How to fetch collection when PK's are known

Posts   
 
    
exp2000
User
Posts: 68
Joined: 13-Apr-2006
# Posted on: 21-Apr-2006 18:05:55   

I need to fetch a collection and I wonder if there easier way to do this.

Dim adapter As New SQLSpecific.DataAccessAdapter Dim toReturn As New EntityCollection(New PublishedUserAlertDetailEntityFactory) Dim bucket As IRelationPredicateBucket = New RelationPredicateBucket Dim expression As IPredicateExpression = New PredicateExpression expression.Add(PredicateFactory.CompareValue(PublishedUserAlertDetailFieldIndex.PublishedUserAlertDetailId, ComparisonOperator.Equal, detailIDs(0))) For idx As Integer = 1 To detailIDs.Count - 1 expression.AddWithOr(PredicateFactory.CompareValue(PublishedUserAlertFieldIndex.PublishedUserAlertDetailId, ComparisonOperator.Equal, detailIDs(idx))) Next bucket.PredicateExpression.Add(expression)

            adapter.FetchEntityCollection(toReturn, bucket)

            Return toReturn
JimHugh
User
Posts: 191
Joined: 16-Nov-2005
# Posted on: 21-Apr-2006 19:35:24   

One option is to fetch the entity then add it to the new collection.


Dim adapter As New SQLSpecific.DataAccessAdapter
Dim toReturn As New EntityCollection(New PublishedUserAlertDetailEntityFactory)
Dim detail as new PublishedUserAlertDetail(detailIDs(0))
adapter.FetchEntity(detail)
toReturn.Add(detail)

Another would be to use FieldCompareRangePredicate


' example from Docs
' VB.NET
Dim values As Integer() = New Integer(2) {1, 2, 5}
bucket.PredicateExpression.Add(New FieldCompareRangePredicate( _
    OrderFields.OrderDate, Nothing, values))

exp2000
User
Posts: 68
Joined: 13-Apr-2006
# Posted on: 21-Apr-2006 22:05:04   

Cool, I'll try Range.