Convert SQL to LINQ to SQL

I'm having big problems converting the next SQL to LINQ to SQL, any of which can be helped?

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 is it even better that anyone knows about an automatic SQl to LINQ converter?

+3
source share
4 answers

See this existing stream.

If you decide to do it manually, Linqpad should be helpful.

+4
source

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

, linqer , SQL- LINQ. .

http://www.sqltolinq.com/

+1

linqpad does not convert.

free converter

http://windowsphone.interoperabilitybridges.com/articles/sql-to-linq-converter

Note. Start with SQLite on Windows, not WindowsPhone.

+1
source

To go from LINQ -> SQL, try the following:

        var db = new DBModelDataContext();
        StringBuilder sb = new StringBuilder();
        StringWriter sw = new StringWriter(sb);
        db.Log = sw; //set the writer

        var items = (from rec in db.Table1
                     select rec).ToList();

        var sql = sb.ToString(); //here is the SQL from LINQ.
0
source

Source: https://habr.com/ru/post/1716185/


All Articles