0

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

2 Answers 2

1

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); 
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.