How to do Select All(*) in linq to sql

前端 未结 9 1758
傲寒
傲寒 2020-12-13 01:12

How do you select all rows when doing linq to sql?

Select * From TableA

In both query syntax and method syntax please.

相关标签:
9条回答
  • 2020-12-13 02:09
    from row in TableA select row
    

    Or just:

    TableA
    

    In method syntax, with other operators:

    TableA.Where(row => row.IsInteresting) // no .Select(), returns the whole row.
    

    Essentially, you already are selecting all columns, the select then transforms that to the columns you care about, so you can even do things like:

    from user in Users select user.LastName+", "+user.FirstName
    
    0 讨论(0)
  • 2020-12-13 02:13
    using (MyDataContext dc = new MyDataContext())
    {
        var rows = from myRow in dc.MyTable
                   select myRow;
    }
    

    OR

    using (MyDataContext dc = new MyDataContext())
    {
        var rows = dc.MyTable.Select(row => row);
    }
    
    0 讨论(0)
  • 2020-12-13 02:16

    Why don't you use

    DbTestDataContext obj = new DbTestDataContext();
    var q =from a in obj.GetTable<TableName>() select a;
    

    This is simple.

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