c# - How to inner join(filtering for nested properties) with expression tree? -
my users should able configure filter result database. decided use expression tree, flexible query. have problems expression tree filtering referencecode.
entities:
pumpstartup
duration (timespan)
dutdbid (guid/fk)
timestamp (datetime)
dut (deviceundertest)
deviceundertest
adminid (string/unique)
dbid (guid/pk)
referencecode (string)
startups (list)
here part of filter in equivalent linq. linq can't use, because don't know how many referencecodes defined user.:
//-------------------reference code filter--------------------------- var query = context.pumpstartups.where((p => p.dut.referencecode == "hkr566" || p.dut.referencecode == "hsh967" || . . .)); startups = query.tolist();
for filtering deviceundertest part of filter, solution is:
// --------------------duts filter----------------------------------- expression dutsexpression = null; expression psuexpression = expression.parameter(typeof(pumpstartup), "psu"); expression psudutidexpression = expression.property(psuexpression, "dutdbid"); foreach (var dut in filter.duts) { deviceundertest deviceundertest = context.devicesundertest.where(d => d.adminid == dut.id).single(); expression dutidexpression = expression.constant(deviceundertest.dbid); expression dutexpression = expression.equal(pumpstartupdutidexpression, dutidexpression); if (dutsexpression == null) { dutsexpression = dutexpression; } else { dutsexpression = expression.or(dutsexpression, dutexpression); } }
how can filter referencecode in manner:
use this:
var dutexpression = expression.property(psuexpression, "dut"); var referencecodeexp = = expression.property(dutexpression, "referencecode "); var constexpr = expression.constant("hkr566"); var eqexp = expression.equal(referencecodeexp , constexpr); dutsexpression = expression.or(dutsexpression, eqexp);
Comments
Post a Comment