0

I have this part of code:

ViewBag.myFeedbacks = db.feedbacks.Where(f => f.project_id ?)

what should I replace char ? , when I want define something like this :

project_id IN (1,2,3)

so, select all feedback, which have project_id from list of values?

Rahul Singh
  • 21,038
  • 6
  • 37
  • 55

3 Answers3

3
ViewBag.myFeedbacks = db.feedbacks.Where(f => new[]{1,2,3}.Contains(f.project_id));

IQueryable.Contains is specialized to emit ... in ... SQL code.

Blindy
  • 60,429
  • 9
  • 84
  • 123
2
var projectIds = new[]{1, 2, 3};

ViewBag.myFeedbacks = db.feedbacks.Where(f => projectIds.Any(p => p == f.project_id))
vidalsasoon
  • 4,318
  • 1
  • 31
  • 40
1

Something like this:

db.feedbacks.Where(f => yourArray.Contains(f.project_id))
xZ6a33YaYEfmv
  • 1,806
  • 4
  • 24
  • 43
  • http://stackoverflow.com/questions/7897630/why-does-the-contains-operator-degrade-entity-frameworks-performance-so-drama – vidalsasoon Nov 03 '15 at 18:55
  • please specify your question or comment to my answer. if it's connected to bad performance of `Contains` expression I must assure you that since EF6 this was successfully fixed and works relatively fast now. – xZ6a33YaYEfmv Nov 03 '15 at 18:58
  • just in case he wasn't using EF6+ which is quite possible. – vidalsasoon Nov 03 '15 at 20:05