c# - The LINQ expression node type 'Invoke' is not supported in LINQ to Entities -
i have problem trying implement filtering expression filter list of entities :
the linq expression node type 'invoke' not supported in linq entities.
this code :
public ilist<documententry> getdocumententriesforrateadjustmenttry2( string username, rate rate, list<rateperiod> rateperiods) { var dimensionlibmanager = new dimensionlibmanager(); var currentversionrategroups = rate.currentrateversion.rategroups.tolist(); expression<func<documententry, ilist<rategroup>, int, bool>> dimensionmatchesexpression = (documententry, rategroups, dimensioninfoid) => rategroups.any( rg => rg.dimension1.all(character => character == '*') || documententry.documententrydimensions.any( ded => ded.dimensioninfo.position == dimensioninfoid && dimensionlibmanager.getdimensionsegments(rate.companyid, username, dimensioninfoid, ded.value).any( seg => ded.value.substring(seg.segmentstart, seg.segmentlength) == seg.segmentvalue))); var dimensionmatches = dimensionmatchesexpression.compile(); var documententries = this.objectset.where(de => dimensionmatches(de, currentversionrategroups, 1)); var result = documententries.tolist(); // error happens here. return result; }
i suspect dimensionmatchesexpression cannot traduced sql because inside calls library's method (dimensionlibmanager.getdimensionsegments) filter documents based on specific parameters.
is there way (other using linqkit or additionnal extention library) can make work ?
the reason why want use expression act filter because, ultimately, to :
var documententries = this.objectset.where(de => dimensionmatches(de, currentversionrategroups, 1) && dimensionmatches(de, currentversionrategroups, 2) && dimensionmatches(de, currentversionrategroups, 3) && dimensionmatches(de, currentversionrategroups, 4));
also, how can debug kind of problem ? error message pretty vague. how can track down exact node causing error ?
i suspect issue.
var documententries = this.objectset.where(de => dimensionmatches(de, currentversionrategroups, 1));
i don't think row number works linq2ef.
public ilist<documententry> getdocumententriesforrateadjustmenttry2( string username, rate rate, list<rateperiod> rateperiods) { var dimensionlibmanager = new dimensionlibmanager(); var currentversionrategroups = rate.currentrateversion.rategroups.tolist(); expression<func<documententry, int, bool>> dimensionmatchesexpression = (documententry, rategroups, dimensioninfoid) => currentversionrategroups.any( rg => rg.dimension1.all(character => character == '*') || documententry.documententrydimensions.any( ded => ded.dimensioninfo.position == dimensioninfoid && dimensionlibmanager.getdimensionsegments(rate.companyid, username, dimensioninfoid, ded.value).any( seg => ded.value.substring(seg.segmentstart, seg.segmentlength) == seg.segmentvalue))); var documententries = this.objectset.where(dimensionmatchesexpression); var result = documententries.tolist(); // error happens here. return result; }
although don't understand why want use expression this. inline all...
just realised few days ago solution problem...bit of hack...
public expression<func<documententry, int, bool>> createwhereclause(stuff); public ilist<documententry> getdocumententriesforrateadjustmenttry2( string username, rate rate, list<rateperiod> rateperiods) { using(var db = new context()) { iqueryable<documententry> foo = db.foos; foreach(var =0; <4; i++) { foo = foo.where(documententry(i)); } } }