What is the fastest way to determine if a row exists using Linq to SQL?

前端 未结 5 1524

I am not interested in the contents of a row, I just want to know if a row exists. The Name column is a primary key, so there will either be 0 or 1 matching row

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-14 00:04

    Of Course

    if (dc.Users.Where(u => u.Name == name).Any())
    

    this is best and if multiple conditions to check then it is very simple to write as

    Say you want to check the user for company then

    if (dc.Users.Where(u => u.ID== Id && u.Company==company).Any())
    

提交回复
热议问题