Fetching Entity from Collection with primary key

Posts   
 
    
MikeP
User
Posts: 40
Joined: 27-May-2007
# Posted on: 16-Feb-2008 15:02:18   

Good Afternoon,

I was wondering what the best way is to fetch an entity from an entitycollection if the primary key value is known. There must be an easier way then:


FlightEntity myFlight;

IPredicate flightFilter = (FlightFields.Id == flightPrimaryKey);
List<int> result = flightCollection.FindMatches(flightFilter);

if (result.Count == 1)
{
      myFlight = flightCollection[result[0]];
}

Thanks,

Mike

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 16-Feb-2008 20:05:21   

Mike, as far as I know, that is the best way of do that. You always can write a specialized method to encapsulate that kind of functionality.