I'm trying to learn LINQ to SQL. I've run into something I just don't get. Here's the LINQ program:
Code:Imports System.IOModule Module1 Sub Main() Dim crs = New DataClasses1DataContext() Dim sw As New StringWriter() crs.Log = sw Dim reports = From report In crs.CRS_Report_Masters Group report By report_id = report.Report_ID Into grouped = Group Select New With { .reportId = report_id, .two = grouped.Sum( Function(row) row.active_report * row.Report_ID) } For Each report In reports Console.WriteLine("{0} {1}", report.reportId, report.two) Next MsgBox(sw.GetStringBuilder().ToString()) End SubEnd Module
Here's the SQL it produces:
Code:SELECT SUM([t1].[value]) AS [two], [t1].[Report_ID] AS [reportId] FROM ( SELECT (-(CONVERT(Float,[t0].[active_report]))) * (CONVERT(Float,CONVERT(Float,[t0].[Report_ID]))) AS [value], [t0].[Report_ID] FROM [dbo].[CRS_Report_Master] AS [t0] ) AS [t1] GROUP BY [t1].[Report_ID] -- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 4.0.30319.1
What I don't get is why there is a minus sign in the SQL before the math in the parentheses. I didn't specify that in the LINQ query.


LinkBack URL
About LinkBacks




Reply With Quote

Bookmarks