-1

I have a List with a Content object ( List<Content>). Inside the Content object, I have 4 fields.

ContentID
ModifiedDate
Description
HtmlMarkup

I have two List<Content> which I need to compare by ContentID (two different databases) and see if any of the fields have different values, and then I need get which fields are different.

So lets say I have object A

ContentID    - 1
ModifiedDate - 1/1/2013
Description  - "This is my first content class"
HtmlMarkup   - "<b>First Content</b>

And object B

ContentID    - 1  -- these are from two different databases, so contentID will match
ModifiedDate - 1/1/2013
Description  - "This is a description"
HtmlMarkup   - "<b>Test</b>

I should be comparing them by ContentID. And with this example I will return that the Description and HtmlMarkup are different for ContentID 1. If there is not match for ContentID (meaning it has been deleted or its not in the second database) I would like to grab that as well. How do I do that?

datatest
  • 483
  • 1
  • 5
  • 14

1 Answers1

2

Not the most elegant solution but something like this should work. Could just modify the select to return whatever data you need.

var result = from contentA in contentObjectA
             join contentB in contentObjectB on contentA.Id equals contentB.Id into contentBB
             from contentB in contentBB.DefaultIfEmpty(null)
             select new {
                ContentAId = contentA.Id
                //Check if Id exists
                ExistsInB = contentB == null ? false : true,
                ModifiedDateDiff = contentB.ModifiedDate == null ? true : contentA.ModifiedDate == contentB.ModifiedDate,
                DescriptionDiff = contentB.Description == null ? true : contentA.Description == contentB.Description,
                HtmlMarkupDiff = contentB.HtmlMarkup == null ? true : contentA.HtmlMarkup == contentB.HtmlMarkup
             };