title: Get objects whose property does not exist in enumerable
body: <p>Multiple answers have led me to the following 2 solutions, but both of them do not seem to be working correctly.</p>
  
  <p>What I have are 2 objects</p>
  
  <pre><code>public class DatabaseAssignment : AuditableEntity
  {
      public Guid Id { get; set; }
      public string User_Id { get; set; }
      public Guid Database_Id { get; set; }       
  }
  
  public class Database : AuditableEntity
  {
      public Guid Id { get; set; }
      public string Name { get; set; }
      public string Server { get; set; }
      public bool IsActive { get; set; }
      public Guid DatabaseClientId { get; set; }
  }
  </code></pre>
  
  <p>Now, the front-end will return all selected Database objects (as IEnumerable) for a given user. I am grabbing all current DatabaseAssignments from the database for the given user and comparing them to the databases by the Database.ID property. My goal is to find the DatabaseAssignments that I can remove from the database. However, my solutions keep returning all DatabaseAssignments to be removed. </p>
  
  <pre><code>if (databases != null)
  {
      var unitOfWork = new UnitOfWork(_context);
      var userDatabaseAssignments = unitOfWork.DatabaseAssignments.GetAll().Where(d =&gt; d.User_Id == user.Id);
  
      //var assignmentsToRemove = userDatabaseAssignments.Where(ud =&gt; databases.Any(d =&gt; d.Id != ud.Database_Id));
      var assignmentsToRemove = userDatabaseAssignments.Select(ud =&gt; userDatabaseAssignments.FirstOrDefault()).Where(d1 =&gt; databases.All(d2 =&gt; d2.Id != d1.Database_Id));
      var assignmentsToAdd = databases.Select(d =&gt; new DatabaseAssignment { User_Id = user.Id, Database_Id = d.Id }).Where(ar =&gt; assignmentsToRemove.All(a =&gt; a.Database_Id != ar.Database_Id));
  
      if (assignmentsToRemove.Any())
      {   
         unitOfWork.DatabaseAssignments.RemoveRange(assignmentsToRemove);
      }
      if (assignmentsToAdd.Any())
      {
         unitOfWork.DatabaseAssignments.AddRange(assignmentsToAdd);
      }
      unitOfWork.SaveChanges();
  }
  </code></pre>