Best way for retrieving single record results in LINQ to SQL

后端 未结 6 1324
清酒与你
清酒与你 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 14:09

    I would use First() or FirstOrDefault().

    The difference: on First() there will be an exception thrown if no row can be found.

提交回复
热议问题