FirstOrDefault with Multiple Conditions

后端 未结 1 1313
悲哀的现实
悲哀的现实 2021-02-05 05:42

In Link to Sql, this works fine:

User user = this.dataContext.Users.FirstOrDefault(p => p.User_ID == loginID);

However, I would like to sear

1条回答
  •  死守一世寂寞
    2021-02-05 06:30

    var user = this.dataContext.Users.FirstOrDefault(
         p => p.User_ID == 250 && p.UserName == "Jack");
    

    The p => at the beginning counts for the whole expression. The syntax used here is a shorthand for

    (p) =>
          {
             return p.User_ID == 250 && p.UserName == "Jack";
          }
    

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