i trying examples working found @ http://www.albahari.com/nutshell/predicatebuilder.aspx
i have following code:
public partial class pricelist { public string name { get; set; } public string desc {get;set;} public datetime? validfrom {get;set;} public datetime? validto{get;set;} public static expression> iscurrent() { return p => (p.validfrom == null || p.validfrom <= datetime.now) && (p.validto == null || p.validto >= datetime.now); } } void main() { list pllist = new list() { new pricelist(){ name="billy", desc="skilled", validfrom = datetime.now.adddays(-10.0) , validto= datetime.now.adddays(1.0) }, new pricelist(){ name="jamie", desc="quick study",validfrom =datetime.now.adddays(-10.0) , validto= datetime.now.adddays(1.0) }, new pricelist(){name= "larry", desc= "rookie",validfrom = datetime.now.adddays(-10.0) , validto= datetime.now.adddays(1.0) } }; // method 1 var myresultlist = pllist.where ( p => (p.validfrom == null || p.validfrom <= datetime.now) && (p.validto == null || p.validto >= datetime.now)).dump(); // method 2 pllist.where(pricelist.iscurrent()).dump(); // not work }
my question between method 1 , method 2, iscurrent() method not work functionality of code identical, when call method 2 pricelist.iscurrent() following error.
any suggestions appreciated.
'system.collections.generic.list' not contain definition 'where' , best extension method overload 'system.linq.queryable.where(system.linq.iqueryable, system.linq.expressions.expression>)' has invalid arguments instance argument: cannot convert 'system.collections.generic.list' 'system.linq.iqueryable'
try
pllist.asqueryable().where(pricelist.iscurrent()).dump();
ps, example doesn't compile, i'm guessing mean
public static expression<func<pricelist, bool>> iscurrent() { ...
and
list<pricelist> pllist = new list<pricelist>() ...
Comments
Post a Comment