I have a query with 4 parameters (@p0, @p1, @p2, @p3). When I run this query in my ASP.NET Website using
var data = ent.Database.SqlQuery<QueryItem>(query, params.ToArray()).ToList();
it runs between 5 and 8 seconds, while if I take exactly the same query and I run it in SSMS (adding parameters declaration at the beginning of course):
declare @p0 as datetime = '2022-02-01'
declare @p1 as datetime = '2022-02-01'
declare @p2 as int = 0
declare @p3 as int = 10
then it runs in less than 1 second. I think I'm doing something wrong with parameters.
Any help?