Note that there are some explanatory texts on larger screens.

plurals
  1. POConvert anonymous type to strong type for grouping query?
    text
    copied!<p>I've pieced together some information from other posts but I'm stuck.</p> <p>The first part works fine. Basically I query the database using LINQ and then I loop through the results generating a report.</p> <pre><code>Dim results As System.Linq.IQueryable(Of Bud900Reports.tblBud_CONNECT) If options.Type = reportType.Organization Then results = From p In db.tblBud_CONNECTs _ Where p.TableOldName = "tblFY" &amp; options.FiscalYear And p.DEPTID = options.GroupFilter _ Order By p.SOURCE_CODE, p.ROW_CODE_903 _ Select p ElseIf options.Type = reportType.Division Then 'Here is my problem line End If For each result in results 'loop through code generating report Next </code></pre> <p>Now instead of having three function with alot of dupelicate code, if the reportType is Division I want to run this query and put it into the results set.</p> <pre><code>results = (From p In db.tblBud_CONNECTs _ Where p.TableOldName = "tblFY" &amp; options.FiscalYear And p.DIVISION_CODE = options.GroupFilter _ Group p By p.DIVISION_CODE, p.SOURCE_CODE, p.ROW_CODE_903 Into _ OrigEft = Sum(p.OrigEft), OrigAmt = Sum(p.OrigAmt), ABEft = Sum(p.ABEft), ABAmt = Sum(p.ABAmt) _ Order By DIVISION_CODE, SOURCE_CODE, ROW_CODE_903 _ Select DIVISION_CODE, SOURCE_CODE, ROW_CODE_903, OrigEft, OrigAmt, ABEft, ABAmt) </code></pre> <p>It's the same data just grouped and summed up. But it comes through as an anonymous type. I tried to do "select new tblBud_CONNECTs with {.DIVISION_CODE = DIVISION_CODE, ...}" but it gave me the error of "Explicit construction of entity type tblBud_CONNECTs is not allowed". </p> <p>How can I do what I want? It seems that I should be able to. Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload