lundi 20 novembre 2017

Find intersection of two lists by KeyAttribute and property value

I want to get the intersection of two lists by reflection of the KeyAttribute properties values :

This given me the primary key properties (for composite) :

IEnumerable<PropertyInfo> keys = typeof(T).GetProperties().Where(prop => prop.IsDefined(typeof(KeyAttribute)));

Now, how can I find the intersection of two lists ?

private static ICollection<T> Except<T>(this ICollection<T> source, ICollection<T> toIgnore)
{
    IEnumerable<PropertyInfo> keys = typeof(T).GetProperties().Where(prop => prop.IsDefined(typeof(KeyAttribute)));
    return source.Where(x => ???);
}

The final use case I want is : var result = firstList.Except(second); It must return items of the first list who don't match key properties values with the second list.





Aucun commentaire:

Enregistrer un commentaire