Convert SQL to LINQ to SQL

后端 未结 4 584
盖世英雄少女心
盖世英雄少女心 2020-11-30 14:07

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.Expenses         


        
相关标签:
4条回答
  • 2020-11-30 14:34

    linqpad don't convert.

    free converter

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

    Note: Run with SQLite in Windows, not WindowsPhone necesary

    0 讨论(0)
  • 2020-11-30 14:40

    To go from LINQ -> SQL try this:

            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 讨论(0)
  • 2020-11-30 14:48

    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/

    0 讨论(0)
  • 2020-11-30 14:56

    See this existing thread.

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

    0 讨论(0)
提交回复
热议问题