0

Legacy ASP.NET application uses a LinqDataSource to populate a GridView, but querying the SQL Server view is slow unless OPTION (USE HINT ('FORCE_LEGACY_CARDINALITY_ESTIMATION')) is added to the query.

<asp:LinqDataSource ID="MyDataSource" runat="server"    
    ContextTypeName="MyDataContext"
    OrderBy="Column1, Column2" 
    TableName="MyTable"
    Where="MyId == @Pid &amp;&amp; Oid == @Oid">
    <WhereParameters>
        <asp:Parameter DefaultValue="1" Name="Pid" Type="Int32" />
        <asp:Parameter DefaultValue="1" Name="Oid" Type="Int32" />
     </WhereParameters>
</asp:LinqDataSource>

Is there any way to add an option/hint to a LinqDataSource?

Dale K
  • 25,246
  • 15
  • 42
  • 71
Jonny
  • 1,037
  • 7
  • 15
  • 3
    Perhaps trying to work out why the view doesn't "behave" with the new cardinality estimator would be an idea still. Does the view use nested views? Perhaps it has a non-SARGable clause? Using the hint feels like kicking the can further down the street. – Thom A Jul 19 '23 at 17:52
  • 1
    I think you can call a procedure inside the LinqDataSource, and there you can use whatever hints you want. Don't you have indexes on MyId / Oid though? – siggemannen Jul 19 '23 at 19:49

0 Answers0