none
Can't figure out why its not saving to localdb RRS feed

  • Question

  • I'm using EF 6.0, with a localdb I created. The program executes fine and iterates over what I want, but it does not save to the database at all.I'm using Json.Net library if it makes a difference.

    Any ideas or tips would be appreciated (self-taught and still learning). 

    1. string URL = @"http://randomurl.com";
    2.                 WebRequest wrGETURL;
    3.                 wrGETURL = WebRequest.Create(URL);
    4.                 HttpWebResponse response = wrGETURL.GetResponse() as HttpWebResponse;
    5.  
    6.                 StreamReader responseStream = new StreamReader(response.GetResponseStream());
    7.  
    8.                 var result = responseStream.ReadToEnd();
    9.                 var parsedInformation = JsonConvert.DeserializeObject<RootObject>(result);
    10.                 foreach (var forwardData in parsedInformation.forwards)
    11.                 {
    12.                     Console.WriteLine(forwardData.name + " " + forwardData.twitterURL + " " + forwardData.height + " " + cities);
    13.                     using (var _temp_Player = new DataFetcherDBEntities())
    14.                     {
    15.                         var players = _temp_Player.Set<Player>();
    16.                         players.Add(new Player
    17.                         {
    18.                             player_id = forwardData.id,
    19.                             name = forwardData.name,
    20.                             age = forwardData.age,
    21.                             birthdate = forwardData.birthdate,
    22.                             birthplace = forwardData.birthplace,
    23.                             weight = forwardData.weight,
    24.                             height = forwardData.height,
    25.                             number = forwardData.number,
    26.                             position = forwardData.position,
    27.                             imageUrl = forwardData.imageUrl,
    28.                             twitterURL = forwardData.twitterURL,
    29.                             twitterHandle = forwardData.twitterHandle
    30.                         });
    31.                         _temp_Player.SaveChanges();
    32.                     }
    33.  
    34.                 }


    Sunday, April 12, 2015 7:26 AM

Answers

  • Hello ParityDrive,

    >>I'm using EF 6.0, with a localdb I created. The program executes fine and iterates over what I want, but it does not save to the database at all.

    Please check the bin folder in your project, for a local database, the Visual Studio would create a copied database and all database operations would be saved into this one: https://msdn.microsoft.com/en-us/library/ms246989.aspx, you could check the database in the bin folder or change the Copy to Output Directory property of the file to Do not copy.

    If this does not work, please feel free let me know.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, April 14, 2015 3:18 AM
    Moderator