Getting error when trying to add StoreManagerController

Sep 29, 2012 at 7:08 PM

Hi.

I am on Part 5 of the tutorial. When I try to add the StoreManagerController I get an error saying:

Unable to retrieve metadata for 'MusicStore.Models.Album'. Using the same DbCompiledModel to create context against different types of database servers is not supported. Instead, create a separate DbCompiledModel for each type of server being used.

Apparently VS added some default database when I made the models, I thought I had removed all the code but obviously not. I am entirely new to .NET so all the magic it is doing is unfamiliar to me. I found out I had two databases running and disconnected the wrong one and have checked my code against the source code and haven't found anything else that wasn't supposed to be there.

I am using Microsoft Visual Studio 2012 and am following the tutorial by the letter. Any help is much appreciated.

Oct 9, 2012 at 7:48 PM
Edited Oct 9, 2012 at 7:50 PM

I am on part 5 and am receiving this exact same error!  Does anyone have a solution for this?  I have followed the tutorial step-by-step!

I am doing the tutorial in VB, and have MVC 4 as opposed to MVC 3.

TIA!

Oct 9, 2012 at 8:30 PM
Edited Oct 9, 2012 at 8:36 PM

OK - I am not sure why this is, but I found a workaround for this issue and I thought I would post it for you mnlia in case you are still having trouble.

Go to your web.config file and locate the following line of code that you added in one of the earlier tutorial steps: 

<add name="MusicStoreEntities" connectionString="Data Source=|DataDirectory|MvcMusicStore.sdf" providerName="System.Data.SqlServerCe.4.0"

/> 

Delete it or comment it out and build the project - then create the StoreManagerController and it should work without issue.  Once the controller and all the associated files have been created, then you can add your connection string back to the web.config file.  I am not sure why this connection string existing is causing this error, but this will allow you to finish the tutorial.

 

Nov 23, 2012 at 8:57 PM

Thank you for this solution. It worked great for me.

As you instructed, I commented out the connection string in the web.config file and then I was able to successfully create the StoreManagerController controller as the lesson instructed.

Thanks again,

Micky

Mar 7, 2013 at 6:45 AM
@bjthomps. Thanks, that did it!

/K
Mar 10, 2013 at 8:33 AM
works
Apr 19, 2013 at 1:35 PM
Funciona mesmo!!!

Really works!!!
Apr 20, 2013 at 11:28 PM
Doesn't work for me unfortunately. After commenting out the DB Connection string, I receive the following message:

"Could not load type 'MyMusicStore.Models.Album' from assembly [...]"

Anyone else having this issue?

Also does anybody know the reasons for these two problems?

I'll just try continuing without the scaffolding...
Apr 26, 2013 at 9:09 AM
bjthomps wrote:
OK - I am not sure why this is, but I found a workaround for this issue and I thought I would post it for you mnlia in case you are still having trouble. Go to your web.config file and locate the following line of code that you added in one of the earlier tutorial steps:  <add name="MusicStoreEntities" connectionString="Data Source=|DataDirectory|MvcMusicStore.sdf" providerName="System.Data.SqlServerCe.4.0" />  Delete it or comment it out and build the project - then create the StoreManagerController and it should work without issue.  Once the controller and all the associated files have been created, then you can add your connection string back to the web.config file.  I am not sure why this connection string existing is causing this error, but this will allow you to finish the tutorial.  
Yes! It's works!!!
May 1, 2013 at 1:42 AM
its work for me..
just delete <add name="MusicStoreEntities" connectionString="Data Source=|DataDirectory|MvcMusicStore.sdf" providerName="System.Data.SqlServerCe.4.0" /> or make this become a comment, and you can make StoreManagerController.
May 6, 2013 at 9:52 PM
I had a very similar issue while trying to create the StoreManagerController. The error I got was: "Unable to retrieve metadata for model object MvcMusicStore.Models.Album. Object reference not set to an instance of an object."

What I noticed is that the following line in the web.config files wasn't properly resolved:

<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />

So I went ahead and re-installed the EntityFramework from the Package Manager Console by typing Install-Package EntityFramework, and that solved the problem.

Note: I was following the Music Store tutorial with MVC 4.

Regards,
May 7, 2013 at 12:22 PM
Unsupported Context Type Error when trying to add StoreManagerController. any help?
May 9, 2013 at 4:15 AM
Hey guys, I'm experiencing a different error than everyone else. I have a feeling it has something to do with my version of SQL server installed. It basically says the following:
  • System.Data.Entity.Edm.EdmEntityType: : EntityType 'Album' has no key defined. Define the key for this EntityType.
  • System.Data.Entity.Edm.EdmEntityType: EntityType: EntitySet 'Albums' is based on type 'Album' that has no keys defined.
So did I miss a step in the tutorial somewhere?

I already tried all the other suggestions. It does seem to generate the MusicStoreDBContext connection string when trying to create the controller, even when throwing the error. So I delete the connection string and try again and get the same error as above. Any ideas?
Aug 1, 2013 at 11:36 PM
Edited Aug 1, 2013 at 11:53 PM
bjthomps wrote:
OK - I am not sure why this is, but I found a workaround for this issue and I thought I would post it for you mnlia in case you are still having trouble. Go to your web.config file and locate the following line of code that you added in one of the earlier tutorial steps:  <add name="MusicStoreEntities" connectionString="Data Source=|DataDirectory|MvcMusicStore.sdf" providerName="System.Data.SqlServerCe.4.0" />  Delete it or comment it out and build the project - then create the StoreManagerController and it should work without issue.  Once the controller and all the associated files have been created, then you can add your connection string back to the web.config file.  I am not sure why this connection string existing is causing this error, but this will allow you to finish the tutorial.  
FYI - I had the same issue as the Original Poster, and this fixed my error.

Thanks!

[edit] In order to see the data again, I had to go back and uncomment that line after setting up the StoreManager controller. After a rebuild, I was able to see the rest of the Data.
Aug 28, 2013 at 9:34 PM
I was storing my model in a separated DocumentLibrary project. I had to add the reference to the EntityFramework.dll to my MVC4 project. Hope this will be helpful for someone.
Oct 18, 2013 at 2:57 AM
it helps a lot!! thank you!!
Mar 2, 2014 at 6:02 AM
Thnak you it works....
Apr 9, 2014 at 1:58 PM
tanq it works.............
Aug 6, 2014 at 8:35 PM
The solution by bjthomps works fine to me too.
Thanks.
Oct 31, 2014 at 7:15 PM
Edited Oct 31, 2014 at 7:18 PM
Hello, the error was in the file web.config, if you delete in the providerName__="System.Data.SqlServerCe.4.0_" the .4.0 the error solved. Because the provider name was wrong. Slds
Oct 31, 2014 at 7:16 PM
Edited Oct 31, 2014 at 7:17 PM
Slds