Add Or Condition to Entity in Entity Framework?

You need to do: var results = entityCollection. Where(entity => entity. Property1 == 1 || entity.

Property1 == 2 || entity. Property1 == 3).

I was afraid of that. What I'd like to do is for the same condition to take place every time a query against that table is executed so that I don't have to write the above code each time I hit the table. – Blake Blackwell Apr 2 '10 at 19:52 @Blakewell: Put the query in a utility class so you can reuse it.

– Mark Byers Apr 2 '10 at 19:58 1 @Reed Copsey: Are you missing an entity =>? – Mark Byers Apr 2 '10 at 19:59 @Mark: Not anymore ;) That happens when I goof and reword things too fast.. Thanks. – Reed Copsey Apr 2 '10 at 20:27.

You should also check out predicate builder: albahari.com/nutshell/predicatebuilder.aspx It's a bit more advanced, but if you have to dynamically chain conditions it's your best bet. Foreach (string keyword in keywords) { string temp = keyword; predicate = predicate. Or (p => p.Description.

Contains (temp)); }.

Haven't tried this, but you could try using contains. Not sure about performance, but the code is smaller: int vals = new int { 1, 2, 3, 4 }; var results = entityCollection. Where(entity => vals.

Contains(entity. Property1)).

1 Contains is only supported in EF 4, which hasn't been released yet (it's coming out the 12th with . Net 4). There's is a release candidate on MS's website.

– BlueRaja - Danny Pflughoeft Apr 2 '10 at 21:35 Didn't even think about that - I've been using EF 4 for a while so this seemed normal. – Marek Karbarz Apr 3 '10 at 0:47.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions