c# - LINQ TO ENTITIES USING PREDICATE(Func(x,bool) Not Working -
i have clause predicate fetching records .now if use same in clause predicate(ie func(x,bool) ) returns no records.my impression both equivalent. - see below
var nonpredicate=this.objectset.where(x=>!string.isnullorempty(x.email) && x.email.contains("and")).tolist(); func<model,bool) clause=x=> x=>!string.isnullorempty(x.email) && x.email.contains("and"); var predicateres=this.objectset.where(clause).tolist();
i expected same results in both cases -but first produces 29 record result , second 0 records.
any great
thanks
linq entitites uses expression<func<?,?>>
it's query methods. lambda expressions automatically coersed expression (expression<func<?,?>>
) or delegate (func<?,?>
) depending on type of variable or argument stored in.
// inline expression var nonpredicate = this.objectset.where(x => !string.isnullorempty(x.email) && x.email.contains("and")).tolist(); // delegate type func<model,bool> clausedelegate = x => !string.isnullorempty(x.email) && x.email.contains("and"); // expression type expression<func<model,bool>> clauseexpr = x => !string.isnullorempty(x.email) && x.email.contains("and"); var predicateres = this.objectset.where(clauseexpr).tolist();
expressions object representation of lambda, allows library translate sql communication database. same not possible delegates, since structure compiled il or machine code.
Comments
Post a Comment