I am trying to pick up ASP.Net - and following the mvc tutorial: http://www.asp.net/mvc/tutorials/mvc-music-store-part-4 (Note: I am totally new to the .Net framework, both C# and ASP.Net)
At the beginning the tutorial suggested to use SQL Server Compact 4.0 - But, I got the SQL Server Express installed instead (since I will be using it after, not just for the tutori开发者_如何学Pythonal). I had another question that's been resolved about setting up the db Connection: ASP.Net SQL ConnectionStrings config
Now, obviously the database is empty - the tutorial didnt even say about instantiating the database, other than downloading some asset file for the db "SampeData.cs", and add it to the Global.asax.cs Application_Start method:
System.Data.Entity.Database.SetInitializer(new MvcMusicStore.Models.SampleData());
So I got the DB connected, but now I am getting:
Model compatibility cannot be checked because the database does not contain model metadata. Ensure that IncludeMetadataConvention has been added to the DbModelBuilder conventions.
When I put on debug point - Sometimes the Application_Start method is hit, sometimes it doesnt. However, I never see the Seed method in SampleData.cs ever being hit - so seems to me my problem right now is with seeding the db
Answering my own question here, hopefully this can help:
- Make sure you dont have the database already created
Here is the connection String in Web.config:
< add name="MusicStoreEntities" connectionString="Data Source=DB_NAME;Initial Catalog=MvcMusicStore;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
And now it works and I can move on in my tutorial
精彩评论