Can I use LINQ to compare what is missing, added or updated between two
collections
I have the following class. To make it so I could compare I added an
Equals method:
public ObjectiveDetail()
public int ObjectiveDetailId { get; set; }
public int Number { get; set; }
public string Text { get; set; }
public override bool Equals(object obj)
{
return this.Equals(obj as ObjectiveDetail);
}
public bool Equals(ObjectiveDetail other)
{
if (other == null)
return false;
return this.Number.Equals(other.Number) &&
(
this.Text == other.Text ||
this.Text != null &&
this.Text.Equals(other.Text)
);
}
}
I have two ICollection collections:
ICollection<ObjectiveDetail> _obj1; // Reference
ICollection<ObjectiveDetail> _obj2; // May have more, less or different
objectDetails from the reference.
The common tfield with the collections is ObjectiveDetailId. Is there a
way I can use three LINQ expressions to create:
A collection of rows in _obj2 and not _obj1
A collection of rows in _obj1 and not _obj2
A collection of rows different between _obj1 and _obj2
Note this is similar to another question I asked earlier but I think this
is a bit simpler now I have added the Equals method. uld do this?
No comments:
Post a Comment