2016年10月27日 星期四

[C#] Func vs Expression Func


今天在找一個Performance issue時, 打開Sql profiler突然看到一段EF查詢直接做Full table scan 追了一下原來是傳過去的條件型態宣告為: Func<T,bool>  注意FuncLinqlambda expression中並無法直接轉為sql,必須改為傳遞Expression<Func<T>>


If you want your lambda to be executed in SQL, you need to pass it as an Expression, not a Function.

Func<T> denotes a delegate which is pretty much a pointer to a method and Expression<Func<T>> denotes a tree data structure for a lambda expression.


沒有留言:

張貼留言