1

我正在尝试将此 SQL 查询转换为 LINQ,但未能这样做.. 任何帮助表示赞赏...

SELECT [t0].id,
   sum([t1].[total_Statements]) AS [value],
   sum( [t1].[totalpage] - [t1].[total_Statements]) AS [value2],
   sum( [t1].[total_bad]) AS [value3],
   [t0].[biller_id]
    FROM [dbo].[upload_t] AS [t0]
    left JOIN [dbo].[printer] AS [t1] ON 
    ((CONVERT(NVarChar,[t0].[id])) = [t1].bill])
    where (([t0].[biller_id] = 10) 
    group by [t0].[biller_id],[t0].id,[t0].[date] 
   ORDER BY [t0].[date] DESC
4

2 回答 2

1

您可以下载Linqer的试用版。这将帮助您将 SQL 查询转换为 Linq 查询,并且在此过程中您可能还会学习 Linq。

于 2012-07-31T12:09:38.137 回答
1
var query = 
ctx.upload_t.Where(w1=>w1.biller_id==10)
.join(ctx.printer, t0=>t0.id.ToString(), t1=>t1.bill.ToString(),
(t0,t1) => new {t0.id, t0.biller_id, t1.total_statements, t1.total_page, t1.total_bad,t0.date})
.GroupBy(g1=>new {t0.biller_id,t0.id,t0.date)
.Select(s1=>new{
   s1.Key.id, 
   value=s1.Sum(s2=>s2.total_statements),
   value2=s1.Sum(s2=>s2.total_page-s2.total_statements),
   value3=s1.Sum(s2=>s2.total_bad),
   s1.Key.biller_id, s1.Key.date})
.OrderBy(o1=>o1.date)

如果您可以使用额外的日期列...如果不能,请稍后再进行选择。

于 2012-07-31T12:10:31.997 回答