Best way for retrieving single record results in LINQ to SQL

后端 未结 6 1399
清酒与你
清酒与你 2021-02-01 13:09

If I query a table with a condition on the key field as in:

        var user = from u in dc.Users
                   where u.UserName == usn
                   s         


        
6条回答
  •  耶瑟儿~
    2021-02-01 13:53

    Also it should be noted that First/FirstOrDefault/Single/SingleOrDefault are the point of execution for a LINQ to Sql command. Since the LINQ statement has not been executed before that, it is able to affect the SQL generated (e.g., It can add a TOP 1 to the sql command)

提交回复
热议问题