Wednesday, 18 July 2012

MVCMusicStore with SQL Server 2008

This is what i did to get the ASP.Net xxx example project to work with SQL Server 2008:

1. Created new Database MVCMUSICSTORE
2. Ran script as is with the exception of removing the USE xxx data store reference
3. Database created successfully
4. Changed DB Connection string to:

    <add name="MusicStoreEntities"
     connectionString="Data Source=WEAPONX\BEAST;Initial Catalog=MVCMUSICSTORE;Integrated Security=True"

5. Ran the solution...Got this error:
Model compatibility cannot be checked because the database does not contain model metadata. Ensure that IncludeMetadataConvention has been added to the DbModelBuilder conventions.
6. Followed the steps in this post:
7. Ran the solution...Got this error:
An error occurred while executing the command definition. See the inner exception for details.
INNER EXCEPTION: {"Invalid object name 'dbo.Album'."}
8. After reading a post about how this message can sometimes come about when EF is expecting pluralized Entities and the tables are not pluralized (or vice versa) I looked at the offending line of code:

            return storeDB.Albums
                .OrderByDescending(a => a.OrderDetails.Count())

- comparing that to the table name 'dbo.Album', it seems my solution required EF to pluralize the entities
- so i removed the modifications to MusicStoreEntities.cs as stipulated in the step 6.

9. Ran the works - lovely jubely!

No comments:

Post a Comment