Question: I have two lists I would like to compare them for updated/modified columns.
Compare 2 Lists of the same class and show the different values in a new list
I would like to do this using linq. The only problem is I am dealing with a lot of columns, over excess of 30 columns in each. Any suggestions would be of great help...

```
        //In Dal
        List<PartnerAndPartnerPositionEntity> GetAllPartnerAndPartnerPositionOldDB(int modelId);
        List<PartnerAndPartnerPositionEntity> GetAllPartnerAndPartnerPosition(int modelId);
        //BL
        //get from new db
        var list1= _partnerDAL.GetAllPartnerAndPartnerPosition(modelId);
        //get from old db
        var list2= _partnerDAL.GetAllPartnerAndPartnerPositionOldDB(modelId);

```

Answer: 
Let's assume that:

1. `PartnerAndPartnerPositionEntity` class contains a property named `Id` that represents the unique key of an item

Given the above you can:

Get all properties of your type 

```
var properties = typeof(PartnerAndPartnerPositionEntity).GetProperties();

```

Join the two lists on the `Id` property and iterate through the properties to see which one has changed:

```
var list = list1.Join(list2,
        x => x.Id,
        y => y.Id,
        (x, y) => Tuple.Create(x, y))
    .ToList();

list.Foreach(tuple =>
{
    foreach(var propertyInfo in properties)
    {
        var value1 = propertyInfo.GetValue(tuple.Item1, null);
        var value2 = propertyInfo.GetValue(tuple.Item2, null);
        if(value1 != value2)
            Console.WriteLine("Item with id {0} has different values for property {1}.",
                tuple.Item1,Id, propertyInfo.Name);
    }
});

```
There...this will generate new IL!

```
public static class EqualityHelper
{
    private ConcurrentDictionary<Type, object> _cache = new ConcurrentDictionary<Type, object>();
    public bool AreEqual<T>(T left, T right)
    {
        var equality = (Func<T,T,bool>)_cache.GetOrAdd(typeof(T), CreateEquality<T>());
        return equality(left, right);
    }

    private Func<T, T, bool> CreateEquality<T>()
    {
        var left = Expression.Parameter(typeof(T));
        var right = Expression.Parameter(typeof(T));
        var properties = from x in typeof(T).GetProperties()
                        where x.GetIndexParameters().Any() == false
                        select x;
        var expressions = from p in properties
                        select Expression.Equal(
                            Expression.Property(left, p),
                            Expression.Property(right, p));
        var body = expressions.Aggregate(Expression.AndAlso);
        var lambda = Expression.Lambda<Func<T,T,bool>>(body, new [] {left, right});
        return lambda.Compile();
    }
}

```