转换SQL到的LINQ to SQL转换SQL到的LINQ to SQL(Convert SQL t

2019-05-12 07:18发布

我在下面的SQL转换的LINQ to SQL很大的麻烦,任何一个能够帮帮忙?

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

甚至更好的人知道一个自动的SQL LINQ转换器的?

Answer 1:

见这个现有的线程。

如果您决定做手工, Linqpad应该是有用的。



Answer 2:

我试图linqpad,但它不是用于转换SQL到LINQ,但其实际用途是使用LINQ到SQL替换查询数据库

但是我觉得linqer是正确的选择,如果你喜欢SQL查询转换为LINQ。 你可以从他们的官方网站上下载。

http://www.sqltolinq.com/



Answer 3:

linqpad没有转换。

免费转换器

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

注意:使用SQLite在Windows中运行,而不是WindowsPhone的necesary



Answer 4:

从LINQ去 - > SQL试试这个:

        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.


文章来源: Convert SQL to LINQ to SQL
标签: linq-to-sql