I'm calling a function with query and arguments that's being translated on SQL Server as follow: exec sp_executesql N' select count(distinct(GoodsID)) from Goods with ...