Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert SQL to LINQ to SQL

Tags:

linq-to-sql

I'm having great trouble in converting the following SQL to LINQ to SQL, any one able to help out?

SELECT     dbo.ExpensesGroup.ExpenseGroupId, dbo.ExpensesGroup.Title, SUM(dbo.Expenses.Amount) AS TotalAmount, MAX(dbo.Expenses.DateLastTickled) 
                      AS LastTickledDate, MAX(dbo.ExpensesGroup.DateTime) AS Date, Username
FROM         dbo.Expenses INNER JOIN
                      dbo.ExpensesGroup ON dbo.Expenses.ExpenseId = dbo.ExpensesGroup.ExpensesId
WHERE     dbo.Expenses.Status = 'AwaitingApproval' or dbo.Expenses.Status = 'AwaitingApprovelGrouping'
GROUP BY dbo.ExpensesGroup.ExpenseGroupId, dbo.ExpensesGroup.Title, dbo.Expenses.Username
ORDER BY MAX(dbo.ExpensesGroup.DateTime) DESC, dbo.ExpensesGroup.Title

Or even better anyone know of an automatic SQl to LINQ converter?

like image 500
Coppermill Avatar asked Aug 27 '09 08:08

Coppermill


2 Answers

See this existing thread.

If you decide to do it by hand, Linqpad should be useful.

like image 185
Adrian Grigore Avatar answered Sep 19 '22 13:09

Adrian Grigore


I tried linqpad but its not for converting SQL to linq but its actual use is to replace sql with linq to query your database

however I think linqer is the right choice if you like to convert SQL query to LINQ. you can download it from their official site.

http://www.sqltolinq.com/

like image 24
Mubashar Avatar answered Sep 21 '22 13:09

Mubashar