Entity Framework – comparing the content of two DbContext (EF 6.1)

Did you ever want to compare the content of two DbContext and getting a list of all differences between both.

for example, you have one context containing :

  <Root>
    <AUTHOR>
      <AUT_ID>1</AUT_ID>
      <AUT_FIRSTNAME>Cedric</AUT_FIRSTNAME>
      <AUT_LASTNAME>Dumont</AUT_LASTNAME>
    </AUTHOR>
  </Root>

and another containing :

  <Root>
    <AUTHOR>
      <AUT_ID>1</AUT_ID>
      <AUT_FIRSTNAME>Cedric123</AUT_FIRSTNAME>
    </AUTHOR>
  </Root>

you would like to have a message telling you this:

Found at least 2 Differences :
1 / Author.FirstName Should be [Cedric] but was [Cedric123] – object with AUT_ID : 1
2 / Author.LastName Should be [Dumont] but was [(null)] – object with AUT_ID : 1

then you would probably check this

PM> Install-Package CExtensions.EntityFramework -Pre

and code this


var comparisonResult = await appContext.CompareTo(expectedContext);

var errorMessage = comparisonResult.ToString();

check whole project on github – CExtensions-Net

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s