c# - Expression Tree Errors as IQueryable but works as IEnumerable -


my first foray expression trees linq query has got me stuck. here query works without expression tree:

iqueryable<sampleresult> samples = samples.select(a => new {    = a,    innerquery = _dc.requestedtests    .selectmany(        b => _dc.resultdata.where(x => (x.testnum == b.testnum && b.sampleid == a.sampleid))        .defaultifempty(),        (b, c) => new requestedtestsjoinedresultdata        {             requestedtests = b,             resultdata = c        }).where(joinedtable => ((joinedtable.resultdata.resultid == 1) &&                                 (joinedtable.requestedtests.testid == 38) &&                                 (joinedtable.resultdata.intvalue >= (int32?) 90))     ).select(joinedtable => joinedtable.requestedtests.sampleid) }).where(temp0 => temp0.innerquery.contains(temp0.a.sampleid)).select(temp0 => temp0.a); 

my next move construct expression tree send the middle where() call. expression tree needed dynamically create filter based on user input.

var joinedtableparameter = expression.parameter(typeof(requestedtestsjoinedresultdata),      "joinedtable");  var left = expression.property(joinedtableparameter,     typeof(requestedtestsjoinedresultdata).getproperty("resultdata")); left = expression.property(left,     typeof(resultdata).getproperty("resultid")); var rightconstant = expression.constant(resultfilter.resultid); expression e1 = expression.equal(left, rightconstant);  left = expression.property(joinedtableparameter, typeof(requestedtestsjoinedresultdata)     .getproperty("requestedtests")); left = expression.property(left, typeof(requestedtests)     .getproperty("testid")); rightconstant = expression.constant(resultfilter.testid); expression e2 = expression.equal(left, rightconstant);  var preditcatebody = expression.andalso(e1, e2);  left = expression.property(joinedtableparameter, typeof(requestedtestsjoinedresultdata)     .getproperty("resultdata")); left = expression.property(left, typeof(resultdata)     .getproperty(comparisoncolumn)); rightconstant = expression.constant(resultfilter.resultvalue, type); expression e3 = expression.makebinary(resultfilter.resultcomparison,      left, rightconstant);  preditcatebody = expression.andalso(preditcatebody, e3);  var lambda = expression.lambda<func<requestedtestsjoinedresultdata, bool>>     (preditcatebody, joinedtableparameter); 

the first code block changes this:

.where(joinedtable => ((joinedtable.resultdata.resultid == 1) &&                        (joinedtable.requestedtests.testid == 38) &&                        (joinedtable.resultdata.intvalue >= (int32?)90)) 

to this:

.where(lambda) 

the first code block works iqueryable when using expression tree, 2nd code block, works if change ienumerable. run-time error when using iqueryable:

an exception of type 'system.notsupportedexception' occurred in system.data.linq.dll not handled in user code

additional information: unsupported overload used query operator 'where'.

stacktrace:

at system.data.linq.sqlclient.queryconverter.visitmethodcall(methodcallexpression mc)\r\n @ system.data.linq.sqlclient.queryconverter.visitinner(expression node)\r\n @ system.data.linq.sqlclient.queryconverter.convertouter(expression node)\r\n @ system.data.linq.sqlclient.sqlprovider.buildquery(expression query, sqlnodeannotations annotations)\r\n @ system.data.linq.sqlclient.sqlprovider.system.data.linq.provider.iprovider.execute(expression query)\r\n @ system.data.linq.dataquery1.system.collections.generic.ienumerable<t>.getenumerator()\r\n @ system.linq.systemcore_enumerabledebugview1.get_items()"

edits:

1: custom data model class:

public class requestedtestsjoinedresultdata {     public virtual requestedtests requestedtests { get; set; }     public virtual resultdata resultdata { get; set; } } 

2: debugview of lambdas:

where clause lambda dynamically created expression tree:

.lambda #lambda1<system.func`2[sodak.domain.models.requestedtestsjoinedresultdata,system.boolean]> (sodak.domain.models.requestedtestsjoinedresultdata $joinedtable)  ($joinedtable.resultdatatable).resultid == 1 &&   ($joinedtable.requestedteststable).testid == 38 &&   ($joinedtable.resultdatatable).intvalue >=   .constant<system.nullable`1[system.int32]>(90)   

large lambda hard coded result filters:

.call system.linq.queryable.select(.call system.linq.queryable.where(     .call system.linq.queryable.select(.call system.linq.queryable.select(     .call system.linq.queryable.where( .call system.linq.queryable.select(     .call system.linq.queryable.selectmany( .call system.linq.queryable.where(     .constant(table(samples)), '(.lambda #lambda1)), '(.lambda #lambda2),     '(.lambda #lambda3)), '(.lambda #lambda4f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]]]>)) ,     '(.lambda #lambda5f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]],system.boolean]>)) ,     '(.lambda #lambda6f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]],sodak.domain.models.sampleresult]>)) ,     '(.lambda #lambda7f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]]]>)) ,     '(.lambda #lambda8f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]],system.boolean]>)) ,     '(.lambda #lambda9f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]],sodak.domain.models.sampleresult]>))     .lambda #lambda1(sodak.domain.samples $a) {     ($a.statusid == (system.nullable`1[system.int32])3 ||     $a.statusid == (system.nullable`1[system.int32])4) &&     $a.lab == .constantc__displayclass24_0>(sodak.domain.services.sampleservice+<>c__displayclass24_0).labid }     .lambda #lambda2(sodak.domain.samples $a) {     .call system.linq.queryable.defaultifempty(     .call system.linq.queryable.where( (.constant(sodak.domain.services.sampleservice)._dc).customfields, '(.lambda #lambda10)))      }     .lambda #lambda3( sodak.domain.samples $a, sodak.domain.customfields $b) {     .new sodak.domain.models.sampleresult(){     labcount = (system.int32)$a.labcount, sampleid = $a.sampleid,     accountid = (system.int32)$a.accountid,received = (system.nullable`1[system.datetime])(($a.received).value).date,     completed = (system.nullable`1[system.datetime])(($a.completed).value).date,     speciesid = (system.nullable`1[system.int32])$a.speciesid,     speciescommonname = ($a.seednames).commonname,statusid = (system.int32)$a.statusid,     statusname = ($a.samplestatus).statusname,variety = $a.variety,lot = $a.lot,     carryover = $a.carryover,lab = (system.int32)$a.lab,labid = (system.int32)$a.lab,     testlist = $a.testlist,customfieldname = $b.customfieldname,customfieldnamevalue = $b.customfieldnamevalue     }     } .lambda #lambda4f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]]]>(sodak.domain.models.sampleresult $a) {     .new <>f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]](     $a, .call system.linq.queryable.select( .call system.linq.queryable.where( (.constant(sodak.domain.services.sampleservice)._dc).subaccounts,     '(.lambda #lambda11)), '(.lambda #lambda12))) }     .lambda #lambda5f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]],     system.boolean]>(<>f__anonymoustype1`2[sodak.domain.models.sampleresult,     system.linq.iqueryable`1[system.int32]] $<>h__transparentidentifier0) {     ($<>h__transparentidentifier0.a).accountid == .constantc__displayclass24_0>(sodak.domain.services.sampleservice+<>c__displayclass24_0).accountidloggedin ||     .call system.linq.queryable.contains( $<>h__transparentidentifier0.innerquery,     .constantc__displayclass24_0>(sodak.domain.services.sampleservice+<>c__displayclass24_0).accountidloggedin) }     .lambda #lambda6f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]],     sodak.domain.models.sampleresult]>(<>f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]] $<>h__transparentidentifier0) {     $<>h__transparentidentifier0.a } .lambda #lambda7f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]]]>(     sodak.domain.models.sampleresult $a) { .new <>f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]](     $a, .call system.linq.queryable.select( .call system.linq.queryable.where( .call system.linq.queryable.selectmany(     (.constant(sodak.domain.services.sampleservice)._dc).requestedtests, '(.lambda #lambda13), '(.lambda #lambda14)) , '(.lambda #lambda15)), '(.lambda #lambda16))) }     .lambda #lambda8f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]],system.boolean]>(<>f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]] $temp0) {     .call system.linq.queryable.contains( $temp0.innerquery, ($temp0.a).sampleid) }     .lambda #lambda9f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]],sodak.domain.models.sampleresult]>(<>f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]] $temp0) { $temp0.a }     .lambda #lambda10(sodak.domain.customfields $x) {     $x.sampleid == $a.sampleid && $x.onreport == (system.nullable`1[system.boolean])true } .lambda #lambda11(sodak.domain.subaccounts $b) {     $b.sampleid == $a.sampleid } .lambda #lambda12(sodak.domain.subaccounts $b) { $b.accountid } .lambda #lambda13(sodak.domain.requestedtests $b) {     .call system.linq.queryable.defaultifempty(.call system.linq.queryable.where( (.constant(sodak.domain.services.sampleservice)._dc).resultdata, '(.lambda #lambda17))) }     .lambda #lambda14( sodak.domain.requestedtests $b, sodak.domain.resultdata $c) { .new sodak.domain.models.requestedtestsjoinedresultdata(){     requestedteststable = $b, resultdatatable = $c } } .lambda #lambda15(sodak.domain.models.requestedtestsjoinedresultdata $joinedtable) {     $joinedtable != null && ($joinedtable.resultdatatable).resultid == 1 && ($joinedtable.requestedteststable).testid == 38 && ($joinedtable.resultdatatable).intvalue >= (system.nullable`1[system.int32])90 }     .lambda #lambda16(sodak.domain.models.requestedtestsjoinedresultdata $joinedtable) { ($joinedtable.requestedteststable).sampleid }      .lambda #lambda17(sodak.domain.resultdata $x) { $x.testnum == $b.testnum && $b.sampleid == $a.sampleid } 

large lambda dynamically created result filters expression tree building.

.call system.linq.queryable.select( .call system.linq.queryable.where( .call system.linq.queryable.select( .call system.linq.queryable.select( .call system.linq.queryable.where( .call system.linq.queryable.select( .call system.linq.queryable.selectmany( .call system.linq.queryable.where( .constant(table(samples)), '(.lambda #lambda1)), '(.lambda #lambda2), '(.lambda #lambda3)), '(.lambda #lambda4f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]]]>)) , '(.lambda #lambda5f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]],system.boolean]>)) , '(.lambda #lambda6f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]],sodak.domain.models.sampleresult]>)) , '(.lambda #lambda7f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]]]>)) , '(.lambda #lambda8f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]],system.boolean]>)) , '(.lambda #lambda9f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]],sodak.domain.models.sampleresult]>)) .lambda #lambda1(sodak.domain.samples $a) { ($a.statusid == (system.nullable`1[system.int32])3 || $a.statusid == (system.nullable`1[system.int32])4) && $a.lab == .constantc__displayclass24_0>(sodak.domain.services.sampleservice+<>c__displayclass24_0).labid } .lambda #lambda2(sodak.domain.samples $a) { .call system.linq.queryable.defaultifempty(.call system.linq.queryable.where( (.constant(sodak.domain.services.sampleservice)._dc).customfields, '(.lambda #lambda10))) } .lambda #lambda3( sodak.domain.samples $a, sodak.domain.customfields $b) { .new sodak.domain.models.sampleresult(){ labcount = (system.int32)$a.labcount, sampleid = $a.sampleid, accountid = (system.int32)$a.accountid, received = (system.nullable`1[system.datetime])(($a.received).value).date, completed = (system.nullable`1[system.datetime])(($a.completed).value).date, speciesid = (system.nullable`1[system.int32])$a.speciesid, speciescommonname = ($a.seednames).commonname,statusid = (system.int32)$a.statusid, statusname = ($a.samplestatus).statusname,variety = $a.variety, lot = $a.lot, carryover = $a.carryover,lab = (system.int32)$a.lab,labid = (system.int32)$a.lab, testlist = $a.testlist,customfieldname = $b.customfieldname,customfieldnamevalue = $b.customfieldnamevalue } } .lambda #lambda4f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]]]>(sodak.domain.models.sampleresult $a) { .new <>f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]]( $a, .call system.linq.queryable.select( .call system.linq.queryable.where( (.constant(sodak.domain.services.sampleservice)._dc).subaccounts, '(.lambda #lambda11)), '(.lambda #lambda12))) } .lambda #lambda5f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]],system.boolean]> (<>f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]] $<>h__transparentidentifier0) { ($<>h__transparentidentifier0.a).accountid == .constantc__displayclass24_0>(sodak.domain.services.sampleservice+<>c__displayclass24_0).accountidloggedin || .call system.linq.queryable.contains( $<>h__transparentidentifier0.innerquery, .constantc__displayclass24_0>(sodak.domain.services.sampleservice+<>c__displayclass24_0).accountidloggedin) } .lambda #lambda6f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]],sodak.domain.models.sampleresult]>(<>f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]] $<>h__transparentidentifier0) { $<>h__transparentidentifier0.a } .lambda #lambda7f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]]]>(sodak.domain.models.sampleresult $a) { .new <>f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]]( $a, .call system.linq.queryable.select( .call system.linq.queryable.where( .call system.linq.queryable.selectmany( (.constant(sodak.domain.services.sampleservice)._dc).requestedtests, '(.lambda #lambda13), '(.lambda #lambda14)) , .constantc__displayclass24_1>(sodak.domain.services.sampleservice+<>c__displayclass24_1).lambda) , '(.lambda #lambda15))) } .lambda #lambda8f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]],system.boolean]>(<>f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]] $temp0) { .call system.linq.queryable.contains( $temp0.innerquery, ($temp0.a).sampleid) } .lambda #lambda9f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]],sodak.domain.models.sampleresult]>(<>f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]] $temp0) { $temp0.a } .lambda #lambda10(sodak.domain.customfields $x) { $x.sampleid == $a.sampleid && $x.onreport == (system.nullable`1[system.boolean])true } .lambda #lambda11(sodak.domain.subaccounts $b) { $b.sampleid == $a.sampleid } .lambda #lambda12(sodak.domain.subaccounts $b) { $b.accountid } .lambda #lambda13(sodak.domain.requestedtests $b) { .call system.linq.queryable.defaultifempty(.call system.linq.queryable.where( (.constant(sodak.domain.services.sampleservice)._dc).resultdata, '(.lambda #lambda16))) } .lambda #lambda14( sodak.domain.requestedtests $b, sodak.domain.resultdata $c) { .new sodak.domain.models.requestedtestsjoinedresultdata(){ requestedteststable = $b, resultdatatable = $c } } .lambda #lambda15(sodak.domain.models.requestedtestsjoinedresultdata $joinedtable) { ($joinedtable.requestedteststable).sampleid }  .lambda #lambda16(sodak.domain.resultdata $x) { $x.testnum == $b.testnum && $b.sampleid == $a.sampleid } 

3: went ahead , tried same query using system.linq.dynamic , got error may or may not related.

the clause using dynamic linq:

.where("joinedtable => " +  "((joinedtable.resultdatatable.resultid == " + resultfilter.resultid + ") && " + "(joinedtable.requestedteststable.testid == " + resultfilter.testid + ") && " + "(joinedtable.resultdatatable." + resultfilter.resulttype + " >= " +  resultfilter.resultvaluestring + "))") 

error:

member access 'sodak.domain.requestedtests requestedteststable' of 'sodak.domain.models.requestedtestsjoinedresultdata' not legal on type 'system.linq.iqueryable`1[sodak.domain.models.requestedtestsjoinedresultdata].

4: generated sql when result filters hard coded:

select [t4].[sampleid], [t4].[value] [labcount], [t4].[value2] [lab], [t4].[value3] [labid], [t4].[value4] [accountid], [t4].[value5] [received], [t4].[value6] [completed], [t4].[value7] [speciesid], [t4].[commonname] [speciescommonname], [t4].[value8] [statusid], [t4].[statusname], [t4].[variety], [t4].[lot], [t4].[carryover], [t4].[testlist], [t4].[value9] [customfieldname], [t4].[value10] [customfieldnamevalue] (     select [t0].[sampleid], [t0].[labcount] [value], [t0].[lab] [value2], [t0].[lab] [value3], [t0].[accountid] [value4], convert(date, [t0].[received]) [value5], convert(date, [t0].[completed]) [value6], [t0].[speciesid] [value7], [t2].[commonname], [t0].[statusid] [value8], [t3].[statusname], [t0].[variety], [t0].[lot], [t0].[carryover], [t0].[testlist], [t1].[customfieldname] [value9], [t1].[customfieldnamevalue] [value10], [t0].[statusid], [t0].[lab]     [samples].[samples] [t0]     left outer join [web].[customfields] [t1] on ([t1].[sampleid] = [t0].[sampleid]) , ([t1].[onreport] = @p0)     inner join [seeds].[seednames] [t2] on [t2].[speciesid] = [t0].[speciesid]     left outer join [lookup].[samplestatus] [t3] on [t3].[statusid] = [t0].[statusid]     ) [t4] (exists(     select null [empty]     [samples].[requestedtests] [t5]     left outer join [results].[resultdata] [t6] on ([t6].[testnum] = [t5].[testnum]) , ([t5].[sampleid] = [t4].[sampleid])     ([t5].[sampleid] = [t4].[sampleid]) , ([t6].[resultid] = @p1) , ([t5].[testid] = @p2) , ([t6].[intvalue] >= @p3)     )) , (([t4].[value4] = @p4) or (exists(     select null [empty]     [samples].[subaccounts] [t7]     ([t7].[accountid] = @p5) , ([t7].[sampleid] = [t4].[sampleid])     ))) , (([t4].[statusid] = @p6) or ([t4].[statusid] = @p7)) , ([t4].[lab] = @p8) 

is not supported or doing wrong when construct expression tree?

short answer:

i think tripping handling of nullable filters. if wrap expression.constant around nullable double (or int), i'm not sure compile nicely.

here's 2 debugviews of lambdas pretty-printed:


long answer

hard coded

.call system.linq.queryable.select(    .call system.linq.queryable.where(       .call system.linq.queryable.select(          .call system.linq.queryable.select(             .call system.linq.queryable.where(                .call system.linq.queryable.select(                   .call system.linq.queryable.selectmany(                      .call system.linq.queryable.where(                         .constant(table(samples)),                         '(.lambda #lambda1)                      ),                       '(.lambda #lambda2),                       '(.lambda #lambda3)                   ),                   '(.lambda #lambda4f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]]]>)                ),                '(.lambda #lambda5f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]],system.boolean]>)             ),             '(.lambda #lambda6f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]],sodak.domain.models.sampleresult]>)          ),          '(.lambda #lambda7f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]]]>)       ),       '(.lambda #lambda8f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]],system.boolean]>)    ),    '(.lambda #lambda9f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]],sodak.domain.models.sampleresult]>) )  .lambda #lambda1(sodak.domain.samples $a) {    ($a.statusid == (system.nullable`1[system.int32])3 || $a.statusid == (system.nullable`1[system.int32])4) &&       $a.lab == .constantc__displayclass24_0>(sodak.domain.services.sampleservice+<>c__displayclass24_0).labid  }  .lambda #lambda2(sodak.domain.samples $a) {    .call system.linq.queryable.defaultifempty(       .call system.linq.queryable.where(           (.constant(sodak.domain.services.sampleservice)._dc).customfields,           '(.lambda #lambda10)       )    )  }  .lambda #lambda3( sodak.domain.samples $a, sodak.domain.customfields $b) {    .new sodak.domain.models.sampleresult(){       labcount = (system.int32)$a.labcount,       sampleid = $a.sampleid,       accountid = (system.int32)$a.accountid,       received = (system.nullable`1[system.datetime])(($a.received).value).date,       completed = (system.nullable`1[system.datetime])(($a.completed).value).date,       speciesid = (system.nullable`1[system.int32])$a.speciesid,       speciescommonname = ($a.seednames).commonname,       statusid = (system.int32)$a.statusid,       statusname = ($a.samplestatus).statusname,       variety = $a.variety,       lot = $a.lot,       carryover = $a.carryover,       lab = (system.int32)$a.lab,       labid = (system.int32)$a.lab,       testlist = $a.testlist,       customfieldname = $b.customfieldname,       customfieldnamevalue = $b.customfieldnamevalue    } }  .lambda #lambda4f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]]]>(sodak.domain.models.sampleresult $a) {    .new <>f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]](       $a,       .call system.linq.queryable.select(          .call system.linq.queryable.where(              (.constant(sodak.domain.services.sampleservice)._dc).subaccounts,             '(.lambda #lambda11)          ),           '(.lambda #lambda12)       )    )  }  .lambda #lambda5f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]],system.boolean]>(<>f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]] $<>h__transparentidentifier0) {    ($<>h__transparentidentifier0.a).accountid == .constantc__displayclass24_0>(sodak.domain.services.sampleservice+<>c__displayclass24_0).accountidloggedin ||    .call system.linq.queryable.contains(        $<>h__transparentidentifier0.innerquery,       .constantc__displayclass24_0>(sodak.domain.services.sampleservice+<>c__displayclass24_0).accountidloggedin    )  }  .lambda #lambda6f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]],sodak.domain.models.sampleresult]>(<>f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]] $<>h__transparentidentifier0) {    $<>h__transparentidentifier0.a  }  .lambda #lambda7f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]]]>(    sodak.domain.models.sampleresult $a) {     .new <>f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]](       $a,        .call system.linq.queryable.select(          .call system.linq.queryable.where(             .call system.linq.queryable.selectmany(                (.constant(sodak.domain.services.sampleservice)._dc).requestedtests,                 '(.lambda #lambda13),                 '(.lambda #lambda14)             ),              '(.lambda #lambda15)          ),           '(.lambda #lambda16)       )    )  }  .lambda #lambda8f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]],system.boolean]>(<>f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]] $temp0) {    .call system.linq.queryable.contains(        $temp0.innerquery,        ($temp0.a).sampleid    ) }  .lambda #lambda9f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]],sodak.domain.models.sampleresult]>(<>f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]] $temp0) {     $temp0.a  }  .lambda #lambda10(sodak.domain.customfields $x) {    $x.sampleid == $a.sampleid &&        $x.onreport == (system.nullable`1[system.boolean])true  }  .lambda #lambda11(sodak.domain.subaccounts $b) {    $b.sampleid == $a.sampleid  }  .lambda #lambda12(sodak.domain.subaccounts $b) {    $b.accountid }  .lambda #lambda13(sodak.domain.requestedtests $b) {    .call system.linq.queryable.defaultifempty(       .call system.linq.queryable.where(           (.constant(sodak.domain.services.sampleservice)._dc).resultdata,           '(.lambda #lambda17)       )    ) }  .lambda #lambda14( sodak.domain.requestedtests $b, sodak.domain.resultdata $c) {    .new sodak.domain.models.requestedtestsjoinedresultdata(){       requestedteststable = $b,       resultdatatable = $c    } }  .lambda #lambda16(sodak.domain.models.requestedtestsjoinedresultdata $joinedtable) {    ($joinedtable.requestedteststable).sampleid }  .lambda #lambda17(sodak.domain.resultdata $x) {    $x.testnum == $b.testnum &&       $b.sampleid == $a.sampleid }  .lambda #lambda15(sodak.domain.models.requestedtestsjoinedresultdata $joinedtable) {    $joinedtable != null &&        ($joinedtable.resultdatatable).resultid == 1 &&        ($joinedtable.requestedteststable).testid == 38 &&        ($joinedtable.resultdatatable).intvalue >= (system.nullable`1[system.int32])90  } 

dynamic lambda @ end

.call system.linq.queryable.select(    .call system.linq.queryable.where(       .call system.linq.queryable.select(          .call system.linq.queryable.select(             .call system.linq.queryable.where(                .call system.linq.queryable.select(                   .call system.linq.queryable.selectmany(                      .call system.linq.queryable.where(                         .constant(table(samples)),                         '(.lambda #lambda1)                      ),                       '(.lambda #lambda2),                       '(.lambda #lambda3)                   ),                   '(.lambda #lambda4f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]]]>)                ),                '(.lambda #lambda5f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]],system.boolean]>)             ),             '(.lambda #lambda6f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]],sodak.domain.models.sampleresult]>)          ),          '(.lambda #lambda7f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]]]>)       ),       '(.lambda #lambda8f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]],system.boolean]>)    ),    '(.lambda #lambda9f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]],sodak.domain.models.sampleresult]>) )  .lambda #lambda1(sodak.domain.samples $a) {    ($a.statusid == (system.nullable`1[system.int32])3 || $a.statusid == (system.nullable`1[system.int32])4) &&       $a.lab == .constantc__displayclass24_0>(sodak.domain.services.sampleservice+<>c__displayclass24_0).labid  }  .lambda #lambda2(sodak.domain.samples $a) {    .call system.linq.queryable.defaultifempty(       .call system.linq.queryable.where(           (.constant(sodak.domain.services.sampleservice)._dc).customfields,           '(.lambda #lambda10)       )    )  }  .lambda #lambda3( sodak.domain.samples $a, sodak.domain.customfields $b) {    .new sodak.domain.models.sampleresult(){       labcount = (system.int32)$a.labcount,       sampleid = $a.sampleid,       accountid = (system.int32)$a.accountid,       received = (system.nullable`1[system.datetime])(($a.received).value).date,       completed = (system.nullable`1[system.datetime])(($a.completed).value).date,       speciesid = (system.nullable`1[system.int32])$a.speciesid,       speciescommonname = ($a.seednames).commonname,       statusid = (system.int32)$a.statusid,       statusname = ($a.samplestatus).statusname,       variety = $a.variety,       lot = $a.lot,       carryover = $a.carryover,       lab = (system.int32)$a.lab,       labid = (system.int32)$a.lab,       testlist = $a.testlist,       customfieldname = $b.customfieldname,       customfieldnamevalue = $b.customfieldnamevalue    } }  .lambda #lambda4f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]]]>(sodak.domain.models.sampleresult $a) {    .new <>f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]](       $a,       .call system.linq.queryable.select(          .call system.linq.queryable.where(              (.constant(sodak.domain.services.sampleservice)._dc).subaccounts,             '(.lambda #lambda11)          ),           '(.lambda #lambda12)       )    )  }  .lambda #lambda5f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]],system.boolean]>(<>f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]] $<>h__transparentidentifier0) {    ($<>h__transparentidentifier0.a).accountid == .constantc__displayclass24_0>(sodak.domain.services.sampleservice+<>c__displayclass24_0).accountidloggedin ||    .call system.linq.queryable.contains(        $<>h__transparentidentifier0.innerquery,       .constantc__displayclass24_0>(sodak.domain.services.sampleservice+<>c__displayclass24_0).accountidloggedin    )  }  .lambda #lambda6f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]],sodak.domain.models.sampleresult]>(<>f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]] $<>h__transparentidentifier0) {    $<>h__transparentidentifier0.a  }  .lambda #lambda7f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]]]>(sodak.domain.models.sampleresult $a) {     .new <>f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]](       $a,        .call system.linq.queryable.select(          .call system.linq.queryable.where(             .call system.linq.queryable.selectmany(                (.constant(sodak.domain.services.sampleservice)._dc).requestedtests,                '(.lambda #lambda13),                 '(.lambda #lambda14)             ),             .constantc__displayclass24_1>(sodak.domain.services.sampleservice+<>c__displayclass24_1).lambda          ),          '(.lambda #lambda15)       )    )  }  .lambda #lambda8f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]],system.boolean]>(<>f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]] $temp0) {    .call system.linq.queryable.contains(        $temp0.innerquery,        ($temp0.a).sampleid    ) }  .lambda #lambda9f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]],sodak.domain.models.sampleresult]>(<>f__anonymoustype1`2[sodak.domain.models.sampleresult,system.linq.iqueryable`1[system.int32]] $temp0) {    $temp0.a  }  .lambda #lambda10(sodak.domain.customfields $x) {    $x.sampleid == $a.sampleid &&        $x.onreport == (system.nullable`1[system.boolean])true  }  .lambda #lambda11(sodak.domain.subaccounts $b) {    $b.sampleid == $a.sampleid  }  .lambda #lambda12(sodak.domain.subaccounts $b) {    $b.accountid } .lambda #lambda13(sodak.domain.requestedtests $b) {    .call system.linq.queryable.defaultifempty(       .call system.linq.queryable.where(           (.constant(sodak.domain.services.sampleservice)._dc).resultdata,           '(.lambda #lambda16)       )    ) }  .lambda #lambda14( sodak.domain.requestedtests $b, sodak.domain.resultdata $c) {    .new sodak.domain.models.requestedtestsjoinedresultdata(){       requestedteststable = $b,       resultdatatable = $c    } }  .lambda #lambda15(sodak.domain.models.requestedtestsjoinedresultdata $joinedtable) {    ($joinedtable.requestedteststable).sampleid }  .lambda #lambda16(sodak.domain.resultdata $x) {    $x.testnum == $b.testnum &&       $b.sampleid == $a.sampleid }  .lambda #lambda1<system.func`2[sodak.domain.models.requestedtestsjoinedresultdata,system.boolean]>(sodak.domain.models.requestedtestsjoinedresultdata $joinedtable)     ($joinedtable.resultdatatable).resultid == 1 &&         ($joinedtable.requestedteststable).testid == 38 &&         ($joinedtable.resultdatatable).intvalue >=  .constant<system.nullable`1[system.int32]>(90)   

if diff these 2 text-walls, you'll see they're identical. numbering of lambdas changes inconsequentially. there couple things popping out @ me:

  1. on dynamic side, lambda contained in closure. best make sure variable lambda isn't being re-used. if is, affect expression.
  2. the hard-coded side has null-check, dynamic side doesn't.
  3. it looks last comparison, hard-coded side casting comparing .intvalue int? , dynamic side passing constant int?. think source of problems.

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -