Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.Net DB Seeding

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 tutorial). 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

like image 969
TS- Avatar asked Dec 15 '25 14:12

TS-


1 Answers

Answering my own question here, hopefully this can help:

  1. Make sure you dont have the database already created
  2. 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

like image 149
TS- Avatar answered Dec 17 '25 07:12

TS-



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!