user125140
user125140

Reputation: 41

Linq to entities

I was wondering how i compared to an array of ids in EF1.0

I know in EF4.0 Beta 1 there is a contains methods so it would look something like this

int[] associationIds = GetAssociationIds();
from c in Associations where c.AssociationId.Contains(associationIds) select c;

But how do you do the equivalent in EF1.0

Upvotes: 0

Views: 92

Answers (2)

user125140
user125140

Reputation: 41

The predicatebuilder documentation lists a way to do it without the linqkit so i used that method, its not pretty but it will do the job until EF4.0 comes along. Cheers

Upvotes: 0

Ben M
Ben M

Reputation: 22482

There's no built-in way to do this in EF1. The most commonly used tool for this task is PredicateBuilder.

The solution (using that toolkit) is to build a custom expression that tests AssociationId against each of the ids in your integer array. The resultant expression looks something like this:

int[] associationIds = GetAssociationIds();

// use PredicateBuilder to build this expression using the contents of
// associationIds:

Expression<Func<Association, bool>> testIds = 
    c => c.AssociationId == 1 || c.AssociationId == 2 || c.AssociationId == 5;

And to use it:

var matchingAssociations = db.Associations.Where(testIds);

Upvotes: 1

Related Questions