[EF4] CompiledQuery预编译性能提升 + 数据载入之大彻大悟
生活随笔
收集整理的這篇文章主要介紹了
[EF4] CompiledQuery预编译性能提升 + 数据载入之大彻大悟
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?//實驗證明使用預編譯后,對于需要[多次查詢]的語句,可以提升到于ado.net幾乎相同的性能
????????private?static?readonly?Func<mydbEntities,?string,?IQueryable<product>>?_CompiledQuery?=
??????CompiledQuery.Compile<mydbEntities,?string,?IQueryable<product>>(
?????(db,?pname)?=>?from?p?in?db.product
??????????????????????where?p.ProductName.Contains(pname)
??????????????????????select?p);?
????????private?static?readonly?Func<mydbEntities,?string,?IQueryable<product>>?_CompiledQuery?=
??????CompiledQuery.Compile<mydbEntities,?string,?IQueryable<product>>(
?????(db,?pname)?=>?from?p?in?db.product
??????????????????????where?p.ProductName.Contains(pname)
??????????????????????select?p);?
數據載入:
[延遲載入],是默認的,就是說,比如有產品,產品種類兩張表,一對多的關系.
var proList = from p in db.Product
? ? ? ? ? ? ? ? ? ? select p.?
這個時候并沒有加載Category.?
但是如果調用proList.FirstOrDefault().Category.CategoryName,就會把Category加載出來.
?
[關閉延遲加載]
上面的代碼就用不起了.但是可以通過顯示加載(這個詞不知道對不對)
?var proList = from p in db.Product.include("Category")
? ? ? ? ? ? ? ? ? ? select p.?
?
很簡單一個道理,居然一直沒明白,看來我真的很愚鈍.
接下來想看下Associations,POCO那些,然后還想看clr via C#第三版,當然最想的還是打DOTA.?
?
?
?
轉載于:https://www.cnblogs.com/renjuwht/archive/2011/03/22/1991155.html
總結
以上是生活随笔為你收集整理的[EF4] CompiledQuery预编译性能提升 + 数据载入之大彻大悟的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php mysql 截取字符串长度,my
- 下一篇: 锐捷ap怎么设置_新房装修网络布线方案一