sql server - Entity Framework, variable criteria runs much more slowly -
the following runs <0.3s, constant in predicate condition
iqueryable<fn_getdocumentsforcontact_result> _queriable; var zeus = new zeus(); var uow = new unitofwork(zeus); var sp = new storedprocedureservice(zeus); int _userid = 183494; int totalrecords = 0; int doctype = 2; var predicate = predicatebuilder.true<fn_getdocumentsforcontact_result>(); predicate = predicate.and(x=>x.type == 2); iqueryable<fn_getdocumentsforcontact_result> documents = sp.fn_getdocumentsforcontact(183494) .asexpandable() .where(predicate); _queriable = documents; _queriable.count().dump();
generates following sql:
-- region parameters declare @ctcidnumber int = 183494 declare @p__linq__0 int = 2 -- endregion select [groupby1].[a1] [c1] ( select count(1) [a1] [dbo].[fn_getdocumentsforcontact](@ctcidnumber) [extent1] [extent1].[type] = @p__linq__0 ) [groupby1]
if change:
predicate = predicate.and(x=>x.type == 2);
to
predicate = predicate.and(x=>x.type == doctype);
the same sql still generated, db connection times out.
the sql runs through ssms
, i've tried clearing query cache , running sql through sp_executesql
, in both scenarios query executes in under 1 second. removing linqkit
predicate builder makes no difference either.
my initial instinct have been parameter sniffing, however, query in question calls inline tvf
, understanding ps applies compiled sprocs.
Comments
Post a Comment