0

I am converting all written LINQs to the SQL procedures in my application but here I get stuck and it made me to write my problem here.

Below mentioned code is my LINQ:

Var Tdate= From T in JobProcessedInfo
                Join D in WeeklyReport on T.JobId=D.JobId
                Join B in BatchDetails on B.BatchId=T.BatchId
                Where T.JobAmount>0 And T.ReviewId = 80
                Group By T.BatchId,B.BatchCode into amt=SUM(T.JobAmount)
                Select T.ProcessedDate

In above LINQ , in Group By clause there is a INTO word before amt=SUM(T.JobAmount). I am not getting how i can convert this into SQL statement query.

Here what I created in SQL by following above LINQ:

Select T.ProcessedDate From JobProcessedInfo T 
JOIN  WeeklyReport  D on T.JobId=D.JobId
JOIN  BatchDetails B on B.BatchId=T.BatchId
Where T.JobAmount>0 And T.ReviewId = 80
Group By T.BatchId,B.BatchCode 

Here i am missing SUM(T.JobAmount) because I am not getting where and how to add it in SQL query.

Please help me to understand and to make proper SQL query of above mentioned LINQ.

Rahul Chaudhari
  • 148
  • 1
  • 17
  • 1
    You should check the SQL that's generated from the LINQ statement. Also, the LINQ you show isn't valid VB syntax. – Gert Arnold Mar 14 '23 at 12:05
  • I have checked and both results are different. I just want to convert my LINQ to sql query. If you looks my query fine then i think i am missing something. – Rahul Chaudhari Mar 14 '23 at 12:14
  • The Linq statement you wrote is converted into a SQL statement - you could log that, see [here](https://stackoverflow.com/a/4900379/2590375). Not clear from the quuestion, but if you are using entity framwork or ef core, there are similar posibilities: [EF6 Logging and Interception](https://learn.microsoft.com/en-us/ef/ef6/fundamentals/logging-and-interception) – nilsK Mar 14 '23 at 12:23
  • I don't see what the `into` clause is doing for you, since `amt` isn't used again in the query? – NetMage Mar 14 '23 at 19:19
  • 1
    have you tried using SQL profiler? you will be able to see what SQL query is generated & executed by EF LINQ query – Nitin Sawant Mar 20 '23 at 13:06

0 Answers0