C# ExceptBy() extension method.

The following extension method is used to compare values from two list and it returns entities from the first list which is not present in the second list based on the key that is passed to it.

public static IEnumerable<T> ExceptBy<T, TKey>(this IEnumerable<T> items, IEnumerable<T> other,  Func<T, TKey> getKey)
    return from item in items
           join otherItem in other on getKey(item)
           equals getKey(otherItem) into tempItems
           from temp in tempItems.DefaultIfEmpty()
           where ReferenceEquals(null, temp) || temp.Equals(default(T))
           select item;