I have a multi-tenant database that returns vastly different numbers of rows depending on which tenant is being queried. Lately we are experiencing a parameter sniffing problem where Entity Framework (EF) queries executed against one tenant (TenantID = 1) take much longer than the same query against another tenant (TenantID = 2). I've done some research and determined that EF doesn't support query hints (see this question) that would allow me to force the query to recompile each time. Now I'm wondering if I can intercept the Sql query that is generated by EF and manually append "OPTION (OPTIMIZE FOR UNKNOWN)" before it is executed. Is this possible? Is EF pluggable such that I can modify the generated Sql before it is executed? Are there any examples of how to do this?
Can I modify the sql generated by Entity Framework before it's executed?
1.2k Views Asked by Mike At
1
There are 1 best solutions below
Related Questions in SQL-SERVER
- SQL server not returning all rows
- Big data with spatial queries/indexing
- Conditional null constraint on Null
- SQL Query - Order by String (which contains number and chars)
- Optimising a slow running SQL Server Stored procedure ordered by calculated fields to return a closest match
- Dynamics CRM Publishing Customizations - Multi Developers
- Is there anyway to set the relationship of many tables from Model?
- Implementation of Rank and Dense Rank in MySQL
- ORM Code First versa Database First in Production
- MVC : Insert data to two tables
- Data streams in case of Merge
- table with multiple IDs but seperate notes need sorting (Tried SQL code to make a union query)
- SQL table Partitioning by Year with ColumnStore index implemented on the table
- Defining which network to use for SQL Server 2012 Management Studio
- Fill a week days in a table with preceding Sundays value
Related Questions in ENTITY-FRAMEWORK
- Entity Framework Code First with Fluent API Concurrency `DbUpdateConcurrencyException` Not Raising
- How to get primary key value with Entity Framework Core
- How do you add extra property using join
- Is there anyway to set the relationship of many tables from Model?
- ORM Code First versa Database First in Production
- MVC : Insert data to two tables
- Cannot insert a null into column MVC ASP.NET
- System.ComponentModel.DataAnnotations.Schema namespace conflict
- EF 6 interceptor to set connectionstring
- IQueryable<T> OrderBy<T> Extension Fails with Foreign Key Property
- Linq to Entities filter navigation collection properties
- How to generate entity framework code-first migrations without using the package manager console?
- Entity Framework and abstract class
- Validation DataGridView Windows Forms
- Require tool to trace the LInq Queries in Oracle
Related Questions in MULTI-TENANT
- MultiTenant Application Prevent Tenant Access Data from Other Tenant in Shared Database
- EclipseLink @Multitenant EntityManager/Transaction handling
- django-tenant-schema and domain redirection
- ASP.NET Identity - Filter roles based on company
- Best way to customize CSS for tenants on a multi-tenant app?
- Microsoft Graph API Accessing basic info of a user that is outside tenancy
- How to implement customer subdomain in Spring framework
- Multi-tenant using Aspnet Identity
- Rails apartment with merit gem
- Rails - Redirect to a user's subdomain if it is removed and they are signed in?
- Multitenant scoping using Pundit
- Entity Framework Multi-Tenancy with ASP.NET Identity
- Mongoose and Node.js multi tenant architecture
- Solutions for a Multi-Tenant Platform using Django with Postgresql
- One database per client or all clients in one database?
Related Questions in QUERY-HINTS
- SQL Server : the maximum recursion 100 has been exhausted before statement completion
- optimize for and recompile hint in Oracle?
- How can I use the READPAST hint in NHibernate?
- Oracle SQL ignoring ordered index hint
- MongoDB index use on find all without hint
- OPTION (RECOMPILE) is Always Faster; Why?
- Is it possible to specify fetchgraph/loadgraph in SpringDataJpa @QueryHint annotation
- C# Entity Framework use SQL options/hints
- Is it possible to set a Hibernate Query Hint by default in a Spring Boot application?
- Get SQL Server to use index seek + key lookup instead of clustered index scan, without WITH (FORCESEEK)
- using Hint in a hosted variable?
- Query Performance on case expression
- Put query hint (OPTION) into view in SQL Server
- Oracle LEADING hint -- why is this required?
- How can I choose different hints for different joins for a single table in a query hint?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Have you tried working around the problem? You may be able to force EF to not use a param, e.g.:
...will use a param, but:
...won't, and I'll bet that:
...won't, either.