c# - Entity Framework 5 and SQL Queries -
i facing serious performance issues... query supposed filter products sql directly in database. when execute code, doesn't, , returns products , filters them in c#.
mycontext context = new mycontext(); func<product, bool> query = (p => p.upc.startswith("817")); var products = context.products.where(query).take(10);
i've noticed products variable of type takeiterator. when change code slightly, filtering ok, forces me put query logic directly in same method, want avoid.
mycontext context = new mycontext(); var products = context.products.where(p => p.upc.startswith("817")).take(10);
this second version of undisclosed type visual studio debugger, shows query trying end with, good!
{select top (10) [extent1].[id] [id], [extent1].[brand] [brand], [extent1].[description] [description], [extent1].[upc] [upc] [dbo].[products] [extent1] [extent1].[upc] n'817%'}
i need figure out how func passed argument , execute query in same fashion first c# code excerpt, optimisations of second.
try instead:
mycontext context = new mycontext(); expression<func<product, bool>> query = (p => p.upc.startswith("817")); var products = context.products.where(query).take(10);
and see question reference on why:
why use expression<func<t>> rather func<t>?
the accepted answer there complete don't dare try explain better!
Comments
Post a Comment