'Query Execution Performance issue with dapper and sqlkata

I am using SQL Kata to build the Query and using Dapper for execution where Performance is degrading with the Parameterized Query.

When I run below Query directly in SSMS then it will take nearly 0.35 Seconds where as same Query will take around 9 secs from code to fetch 30000 records.

Even i tried DBType.String and IsAnsi but Still it takes long time to fetch the records from code.

exec sp_executesql N'SELECT [hha], [cgtask_id] FROM [caregivertasks] WHERE [hha] = @p0 AND [cgtask_id] IN (@p1, @p2, @p3,.......)',N'@p0 int,@p1 int,@p2 int,@p3 int',@p0=1,@p1=1651,@p2=1652,@p3=1653,....

Any help is much appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source