'The entity type is not part of the model for the current context.'

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
5 years ago
Hello!  

We have a plugin that we are moving from our 3.6 site to our 4.0 site.  I have been getting the error `The entity type JDECarrierCodeRecord is not part of the model for the current context.` on this code:


public virtual IPagedList<JDECarrierCodeRecord> GetAllCarrierCodes(int pageIndex = 0, int pageSize = 30)
        {
            
                var query = from pnc in _pncRepository.Table
                            orderby pnc.CarrierCode, pnc.CarrierName
                            select pnc;

                var records = new PagedList<JDECarrierCodeRecord>(query, pageIndex, pageSize);
                return records;
            
        }


After lots of struggle, we realized that this code works perfectly on my coworker's machine; however, I get the error on mine.  The environments really should be the same -- and I've been working to verify that.  None of the common answers around Google are helpful because this code works fine on another machine.  It's something on my localhost only.  Unfortunately, my localhost is the system from which we build and deploy things to our dev server, so I need to get it working sparkly on here.  

Can anyone think of some places to check for a cause for this?  Maybe some dependency like Entity Framework is out of order, but I don't see anything.

Thanks!

Jeremy
5 years ago
Does it run fine without the plugin?


5 years ago
Oh, yeah.  Everything runs fine.  Even other plugins that are using the same sort of code to do the same sort of thing work fine.  But this plugin in particular is failing on my machine.  I've uninstalled and reinstalled and cleaned and built and rebuilt and prayed and made mean faces at it.
5 years ago
I got this working, but the solution is still unsettling.  I just created a new directory and cloned the repo for the site from Git into the new directory.  Everything builds and works perfectly there.  I've been comparing the new folder to my existing folder, but I haven't found any relevant differences yet.  Can anyone think of anything I could look for?  I'm back in business now, but I'd love to know what happened so I could prevent it in the future.

Thanks!

Jeremy
5 years ago
I currently have the same kind of problem. Did you reach any conclusion?
5 years ago
Unfortunately, not really.  All I did was create a new directory on my localhost and then clone the solution again from Git.  Whatever was causing my issue was something in my localhost folder, so starting with a fresh copy from source control got me moving again.  I have never figured out what the problem in the old directory was, though.

Jeremy
5 years ago
That's too bad. But thanks for the fast answer.

I'll keep at it.
5 years ago
Everything runs fine.
5 years ago
Guys, I think I have an answer.  Sort of.  I learned today that we cannot init DBContext on the same table in multiple plugins.  So, when I was trying to use the table in plugin A, it was already part of plugin B.  When plugin A ran, it went into the code for plugin B to try to work with that table.  This is where the problem seems to have started for me.  If I uninstall one plugin and remove it from the Plugins folder, nopCommerce doesn't encounter the problem.

Jeremy
5 years ago
Guys,

I have a possibly even better answer.  

`this.RegisterPluginDataContext<TrexJDEObjectContext>(builder, CONTEXT_NAME);`

If I specify a unique name for the context in each plugin, it looks like everything works fine.

Maybe this is obvious, but this is my first experience with some of this stuff.

Jeremy
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.