I am currently trying to complete an MVC3 project called Music Store which is free online. I reached a scaffolding part and I am unable to proceed past this problem. When I try to create a a scaffold I receive a message
Unable to retrieve metadata for ‘MVCMusicStore.Models.Album’. Unable to cast object of type ‘System.Data.Entity.Core.Objects.ObjectContext’ to type ‘System.Data.Objects.ObjectContext’
I just don’t know what to do to get past this point. Any help would be appreciated
Are you using Entity Framework 6? If so scaffolding will not work for EF6 with older MVC versions. It may work with MVC 6.
Otherwise, you would need to go for downgrade to EF 5.
See these references:
http://support.microsoft.com/kb/2816241
http://stackoverflow.com/questions/19513599/scaffolding-entityframework-6-unable-to-cast-object-of-type-system-data-entity
http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_28405505.html
http://stackoverflow.com/questions/16041894/entity-framework-6-unable-to-retrive-metadata
Hi 05beckga,
Thanks for your post.
According to your description,
05beckga
Unable to retrieve metadata for ‘MVCMusicStore.Models.Album’. Unable to cast object of type ‘System.Data.Entity.Core.Objects.ObjectContext’ to type ‘System.Data.Objects.ObjectContext’
Try comment out your connection string and use default when create controller,after creation return your connection string.
Hope this can be helpful.
Best Regards,
Eileen
Hello!
Commenting connections string or replacing it by any default one did no fix the same issue in my case.
So i uninstalled EF 6 and EF for SQLserverCE 4.0( donno why i installed it at all), Then i installed EF 5 and got it work. By the way EF 4 can be found in MusicStore package. I also cleaned up my web.config but it is another story…
Good luck!