last day (15 days later) » 

7:57 PM
0
A: Entity Framework not writing to Database

Praveen PauloseYou need to use _temp_Player.Players.Add instead of Attach. When you Attach, you need to set the entity state for the EF to detect that it is a new record and insert it into the database during Save Changes.

 
Check my comment above.
 
Can you show your connection string?
 
<add name="DataFetcherDBEntities" connectionString="metadata=res://*/EF_Models.DataFetcher.csdl|res://*/EF_Models.‌​‌​DataFetcher.ssdl|res://*/EF_Models.DataFetcher.msl;provider=System.Data.SqlClie‌​nt‌​;provider connection string=&quot;data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\Databases\DataFetcherDB.‌​‌​mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
It was already listed in Server Explorer as the database was created in Visual Studio. And yes I do have it installed.
 
It should work with the Add. Can you update your code in the original post to show your updated code?
 
I switched .Attach to .Add
 
7:57 PM
Out of ideas. That should have worked
 
I don't know either and its frustrating me :(
 
Just to verify if there are records. Can you in code enumerate Players from your entities and print to the Console or just print the count of players?
 
there is 800+ players, the console write line displatys them all.
 
Which means there must be a conflict in the primary key when you are trying to insert these new records
I assume the only way these players go into the database is through your code
 
8:21 PM
yes i am taking a json responss and storing it.
 
So the entries are going to your database. It goes in the first time and the second time it gives you a primary key violation error.
 
9:12 PM
seems like thata the case. when i check the database (which i had to move to bind/debug) there wqs nothing in it.
 
 
2 hours later…
11:07 PM
I seriously don't know wtf is wrong.
 

last day (15 days later) »