0

How can you insert a WHERE IN clause using parameter in net core? They are a list of strings. I have tried everything but doesn't seem to work. Tried String.Join("','",myList) and it looked ok but it doesn't return from the database. Tried the same query on sql server and returns the data as expected.

MohammedT
  • 497
  • 2
  • 5
  • 13
  • That's not really possible as the commas in the list are not treated as delimiters but just a value. However, using dynamic SQL you can work around it: https://stackoverflow.com/questions/5401641/passing-a-sql-parameter-to-an-in-clause-using-typed-datasets-in-net. Be super careful and properly escape the strings; otherwise you create an SQL injection vulnerability. – Codo May 29 '18 at 14:58
  • Thank you for your guidance, I have come up with a solution which is not the best but works perfectly. I return the full list from the database then using linq I query the object using .WHERE(x=>object.Contains(x.item)). This filters out the needed data and returns back what i need. – MohammedT Jun 03 '18 at 19:40

0 Answers0