c# - Error converting SQL with join to LINQ -


i have sql query i'm trying convert linq , having trouble understanding obscure error messages when query enumerated.

the sql query (which works intended), is:

select a.testguid, min(a.starttime) starttime, count(b.testcaseid) numtests, count(dinstinct a.id) numscenarios loadtestsummary join loadtesttestsummarydata b     on a.loadtestrunid = b.loadtestrunid     a.targetstack = env ,     a.testguid not null ,     a.starttime not null ,     a.loadtestrunid not null group a.testguid 

converting linq, following:

var q = in _context.loadtestsummary                     a.targetstack == env &&             a.testguid != null &&             a.starttime != null &&             a.loadtestrunid != null         join b in _context.loadtesttestsummarydata on new         {             loadtestrunid = convert.toint32(a.loadtestrunid)         } equals new         {              loadtestrunid = b.loadtestrunid         }         group new { a, b } new         {             a.testguid         }         g         select new          {             datecreated = g.min(p => p.a.starttime),             numscenarios = g.count(),             testguid = g.key.testguid             numtests = // ???         }; 

two problems have:

1) when query enumerated run-time error i'm having trouble deciphering. query works fine in linqpad, gives me run-time error in program. not sure cause this. staring @ makes head hurt:

argumentexception: expression of type 'system.func``2[microsoft.data.entity.query.entityquerymodelvisitor+transparentidentifier``2[perfportal.models.loadtestsummary,perfportal.models.loadtesttestsummarydata],<>f__anonymoustype7``1[system.string]]' cannot used parameter of type 'system.func``2[<>f__anonymoustype5``2[perfportal.models.loadtestsummary,perfportal.models.loadtesttestsummarydata],<>f__anonymoustype7``1[system.string]]' of method 'system.collections.generic.ienumerable``1[system.linq.igrouping``2[<>f__anonymoustype7``1[system.string],<>f__anonymoustype5``2[perfportal.models.loadtestsummary,perfportal.models.loadtesttestsummarydata]]] _groupby[<>f__anonymoustype5``2,<>f__anonymoustype7``1,<>f__anonymoustype5``2](system.collections.generic.ienumerable``1[<>f__anonymoustype5``2[perfportal.models.loadtestsummary,perfportal.models.loadtesttestsummarydata]], system.func``2[<>f__anonymoustype5``2[perfportal.models.loadtestsummary,perfportal.models.loadtesttestsummarydata],<>f__anonymoustype7``1[system.string]], system.func``2[<>f__anonymoustype5``2[perfportal.models.loadtestsummary,perfportal.models.loadtesttestsummarydata],<>f__anonymoustype5``2[perfportal.models.loadtestsummary,perfportal.models.loadtesttestsummarydata]])'

2) not quite sure how count(distinct a.id) numtests field. looks isn't supported in linq looks other people have asked question may able figure out once #1 resolved.

any thoughts on what's wrong here? not sure error telling me.

all appreciated!

looking @ sql query , linq code, came this:

from in loadtestsummary join b in loadtesttestsummarydata      on a.loadtestrunid equals b.loadtestrunid      a.targetstack == env &&     a.testguid != null &&     a.starttime != null &&     a.loadtestrunid != null group new { a, b } a.testguid g select new  {     testguid = g.key,     datecreated = g.min(el => el.a.starttime),     numtests = g.select(el => el.b.testcaseid).count(),     numscenarios = g.select(el => el.a.id).distinct().count() }; 

note, don't need convert loadtestrunid int, may use standard string comparision.

that horrendous error caused grouping , comparing using anonimous objects, thou prefer not read error it's eldritch abomination not ment seen nor comprehend mere mortals, seems.


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -