Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use Contains:

var result = db.History.Where(x => x.Status == 'Created' && list.Contains(x.HistoryId))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading