Advertisement
Guest User

Untitled

a guest
Oct 20th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. if(isDbEmpty("books"))
  2. {
  3. using (StreamReader r = new StreamReader("Books.json"))
  4. {
  5. string json = r.ReadToEnd();
  6. List<Book> Books = JsonConvert.DeserializeObject<List<Book>>(json);
  7.  
  8. foreach(var b in Books)
  9. {
  10. _db.Books.Add(new Book{
  11. Title = b.Title,
  12. AuthorFirstName = b.AuthorFirstName,
  13. AuthorLastName = b.AuthorLastName,
  14. PublishDate = b.PublishDate,
  15. ISBN = b.ISBN
  16. });
  17. }
  18. _db.SaveChanges();
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement