Skip to content
Advertisement

How do you write a parameterized where-in raw sql query in Entity Framework

How do you write a parameterized where-in raw sql query in Entity Framework? I’ve tried the following:

But as expected, it throws an error on DateParam because it’s expecting a single value.

Advertisement

Answer

This isn’t a problem specific to entity-framework, you can solve it by generating your own parameter names dynamically.

The resulting query sent to SQL-Server will look like the following:

Generally, you want to avoid doing string manipulation when writing queries, however, I believe this example is safe from sql-injection.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement