Home > database >  How to convert SQL to LINQ where it contains IN keyword in statement
How to convert SQL to LINQ where it contains IN keyword in statement

Time:11-23

I have got this SQL statement which I am trying to convert to LINQ.

SELECT * 
FROM History 
WHERE Status = 'Created' AND HistoryId IN (1, 2, 3);

I have not been able to do the IN part. Tried following but I am unable to complete it:

var list = new List<int>() { 1, 2, 3};
var result = db.History.Where(x => x.Status == 'Created' && )

How do I write IN part of SQL in LINQ?

CodePudding user response:

You can use Contains:

var result = db.History.Where(x => x.Status == 'Created' && list.Contains(x.HistoryId))
  • Related