3 ms·
> There is a reason I wrapped everything in Expression<> to avoid the mistake I made way too often when sending a Func<T,bool> to an EF context. Sorry, I did n
by jeswin 7y ago
> There is a reason I wrapped everything in Expression<> to avoid the mistake I made way too often when sending a Func<T,bool> to an EF context.
Sorry, I did not follow.
- scarface74 7y agoNothing will stop you from passing in a Func<T,bool> type where you should be using an expression, but if you pass it to a Where on an EF context it will be run on the client instead of being converted to sql.
- jeswin 7y agoI was saying that Expression Trees are created at "compile-time", and not at runtime. Here's the CIL that gets generated in the case of IQueryable - https://stackoverflow.com/questions/3894598/how-is-linq-compiled-into-the-cil https://stackoverflow.com/questions/3894598/how-is-linq-comp...
- nightski 7y agoThere is an entire API for building up dynamic expression trees and compiling them at runtime.
- mythz 7y ago...and zero for the inverse, which is why Expression Trees are generated by the C# compiler at compile time, not decompiled at runtime.
- nightski 7y agoYou are right (as far as built in support goes), but it actually could be a fun project to take IL and build up C# expression trees from it. Especially given there are plenty of IL to C# de-compilation libraries out there.
- nizmow 7y agoIn EF Core 3.x it'll now throw an exception at runtime.