开发者

Compiled query using list of class objects in C#

开发者 https://www.devze.com 2022-12-24 01:30 出处:网络
Can somebody help me out in creating compiled queries where input is to be a list of class objects? I have seen examples where Func<DataContext, somematchobject, IQueryable<T>> is created

Can somebody help me out in creating compiled queries where input is to be a list of class objects? I have seen examples where Func<DataContext, somematchobject, IQueryable<T>> is created and compiled. But can I do something like Func<List<T>, matchObject, T>, and compile it? Basically I want an object(T) meeting certain conditions (as in matchObject) to be returned fro开发者_StackOverflow中文版m a list of objects(List<T>).

Will CompiledQuery.Compile help me in this? Please help me experts!!


var selected = from item in list
               where item.Matches(matchObject)
               select item;

or

var selected = list.Where(item => item.Matches(matchObject));


I used a Func, matchObject, T> Fn (say). And built an Expression,matchObject,T>> Ex (say) where I gave the match conditions. And Fn = Ex.Compile(), and its done. Whenever I want a particular object I would create a matchObject and call Fn(List, matchObject), it would return me my T object. Thanks for all your help!!

0

精彩评论

暂无评论...
验证码 换一张
取 消