[Entity Framework] 於查詢時移除不必要的check null where clause

有時當進行performance tuning 時, 有時會在ORM 層面遇到問題. 檢查記錄後, 發覺原來透過Entity Framework 將LINQ 或Lambla express 轉換成SQL 時會出產生了不必要的Check null, 從而使Index 不能觸發, 亦因此令執行時間變長.

要解決的話, 只須在DbContext 中Disable 其設定便可.

public class DataContext : DbContext
{
    public DataContext()
    {
        this.Configuration.UseDatabaseNullSemantics = true;
    }
}

參考資料

 

About C.H. Ling 262 Articles
a .net / Java developer from Hong Kong and currently located in United Kingdom. Thanks for Google because it solve many technical problems so I build this blog as return. Besides coding and trying advance technology, hiking and traveling is other favorite to me, so I will write down something what I see and what I feel during it. Happy reading!!!

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.