Why would you use Expression> rather than Func?

后端 未结 10 2013
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 00:32

I understand lambdas and the Func and Action delegates. But expressions stump me.

In what circumstances would you use an Expression

10条回答
  •  心在旅途
    2020-11-22 01:07

    I don't see any answers yet that mention performance. Passing Func<>s into Where() or Count() is bad. Real bad. If you use a Func<> then it calls the IEnumerable LINQ stuff instead of IQueryable, which means that whole tables get pulled in and then filtered. Expression> is significantly faster, especially if you are querying a database that lives another server.

提交回复
热议问题