Explore Courses Blog Tutorials Interview Questions
0 votes
in SQL by (20.3k points)

What is the best way to write a query with IN clause using Dapper ORM when the list of values for the IN clause is coming from business logic? For example, let's say I have a query:


  FROM SomeTable 

 WHERE id IN (commaSeparatedListOfIDs)

The commaSeparatedListOfIDs is being passed in from business logic and it can be any type of IEnumerable(of Integer). How would I construct a query in this case? Do I have to do what I've been doing so far which is basically string concatenation or is there some sort of advanced parameter mapping technique that I'm not aware of?

1 Answer

0 votes
by (40.7k points)

For Dapper this is valid. 

As for example:

string sql = "SELECT * FROM SomeTable WHERE id IN @ids"

var results = conn.Query(sql, new { ids = new[] { 1, 2, 3, 4, 5 }});

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Oct 5, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

30.5k questions

32.5k answers


108k users

Browse Categories