Home > Net >  linq for records not having a value
linq for records not having a value

Time:08-01

I have table with values

  Table Event

     Id     UserId      EventId
   ===========================
     1        1           1
     2        1           2
     3        1           3
     4        2           2


   Table Users

     Id     FirstName    LastName
   ===========================
     1        xx          xx-last
     2        ww          ww-last
     3        dd          dd-last
     4        qq          qq-last

I want to have the list of users which forexample don't have EventId=1. in this case it would be User 2,3,4

how can i make it with linq

CodePudding user response:

Assuming that your User entity has an Events navigation property:

var usersWithoutEvent1 = dbContext.Users
    .Where(u => u.Events.All(e => e.Id != 1))
    .ToArrayAsync();
  • Related