I am using the following LINQ to compare two lists of objects.
var upd = newObj.Where(wb => oldObj.Any(db =>
(db.AnswerId == wb.AnswerId) &&
(db.Number != wb.Number || !db.Text.Equals(wb.Text))))
.ToList();
When the AnswerId matches then I look to see if the object.Number or the object.Text is different.
However this is giving me an:
Object reference not set to an instance of an object.
I think the problem is when the old object has an answer with Text field set to null so
!db.Text.Equals(wb.Text)
fails to work the way I expected.
Is there some way I could change the above comparison so it shows true if the text is different or if the old Text was null and also if the values of the field named Correct change?
FYI Here's the object I am using:
public class Answer {
public int AnswerId { get; set; }
public int Number { get; set; }
public int QuestionId { get; set; }
public Nullable<bool> Correct { get; set; }
public Nullable<bool> Response { get; set; }
public string Text { get; set; }
}