Home > English > Load operation failed for query ‘Getcustomer’. The metadata stored by the ObjectContext is different than the metadata stored by the ObjectContext’s connection. This can happen if the connection string is changed after the ObjectContext is created.

Load operation failed for query ‘Getcustomer’. The metadata stored by the ObjectContext is different than the metadata stored by the ObjectContext’s connection. This can happen if the connection string is changed after the ObjectContext is created.

This exception goes hand in hand with my previous blog posts on dynamically changing the connection string in Entity Framework. If you override CreateObjectContext(), you need to be sure that you don’t first create an instance of your entities and then try and pass in the connection string by setting the property.

The following is an example of what will cause the exception:

protected override CustomerEntities CreateObjectContext()
{
    string connectionString = ...
    ...
    ctx = new GrantsManagementEntities();
    ctx.Connection.ConnectionString = connectionString;

    return ctx;
}

Assuming we had a valid connection string, you would get the exception as listed in the title of this post.

The way to correct this issue is to do the following:

protected override CustomerEntities CreateObjectContext()
{
    string connectionString = ...
    ...
    ctx = new GrantsManagementEntities(connectionString);

    return ctx;
}

This allows for having dynamic connection strings on your WCF RIA Service.

Hope this helps…

Advertisements
  1. May 31, 2010 at 2:21 pm

    Really great article. Honest!

  1. No trackbacks yet.

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

%d bloggers like this: