nnmmss
nnmmss

Reputation: 2992

linq for records not having a value

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

Upvotes: 0

Views: 39

Answers (1)

Good Night Nerd Pride
Good Night Nerd Pride

Reputation: 8470

Assuming that your User entity has an Events navigation property:

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

Upvotes: 1

Related Questions