3

I am creating a plug-in in Nopcommerce and have created a database table using my plugin.

In that plug-in I have used GetListByProductId(int id) & InsertItem(Item item) methods in services.

I have implemented these methods like below:

        public void InsertItem(itemList item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("itemlist");
            }

            //Persist
            _itemlistRepository.Insert(item);
        }


        public virtual ItemList GetListByProductid(int ProductId)
        {
            if (ProductId <= 0) return null;

            return _itemlistRepository.GetById(ProductId);

        }

But I am getting the error, “The model backing the 'ItemObjectContext' context has changed since the database was created”.

I don't understand why this error happens and from where.

Can anyone help me solve this problem?

All answers are accepted.

Thanks in anticipation.

Abhay Andhariya
  • 1,989
  • 3
  • 16
  • 24
  • Could you check following link? http://stackoverflow.com/questions/3600175/the-model-backing-the-database-context-has-changed-since-the-database-was-crea/13655533#13655533 – Max Oct 21 '13 at 10:28
  • Hey, thanks but I have already added Database.SetInitializer(null); in both my Install() & UnInstall() Methods. – Abhay Andhariya Oct 21 '13 at 11:13
  • Did you look into the official documentation on creating a data plugin? http://www.nopcommerce.com/docs/75/plugin-with-data-access.aspx – Max Oct 21 '13 at 11:15
  • I have created my plugin using this reference. – Abhay Andhariya Oct 21 '13 at 12:02
  • possible duplicate of [Entity Framework Code Only error: the model backing the context has changed since the database was created](http://stackoverflow.com/questions/3552000/entity-framework-code-only-error-the-model-backing-the-context-has-changed-sinc) – Gustav Bertram Feb 28 '14 at 09:36

1 Answers1

2

I've been having the same issue. In our case we have reverse-engineered a code-first design based on an existing database. The new database is undergoing enhancements to its design.

Typically when modifying the database structure I would drop the DB and then have it re-generated by the code.

This is all very well and good until you start migrating data, then changing the structure a little more (all still under development)

so dropping/re-creating becomes a huge pain during development.

What I did to resolve this issue was simply delete the entry in the table dbo.__MigrationHistory that is created by the code-first implementation. This row contains a hashed up version of the model and is what's, as my understanding goes, is checked when you fire up your app.

May or may not be the right thing to do, though during development it makes sense to me :)

Darren Wainwright
  • 30,247
  • 21
  • 76
  • 127
  • Hey, thanx Darren for your help, actually i have found another solution is that i have just put Database.SetInitializer(null); line in my service file's constructor and problem is solved. – Abhay Andhariya Oct 23 '13 at 09:32
  • Ah ok, cool. Wasn't sure if that would cause the same problem when you do actually need to set an initializer. – Darren Wainwright Oct 23 '13 at 13:27