protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         db.Dispose();
     }
     base.Dispose(disposing);
 }
Esempio n. 2
0
        private static void Main()
        {
            // The Bookstore.sql script is in the \Resources folder of the Models project.

            BookstoreEntities bookstoreContext = null;

            try
            {
                XPathDocument     doc        = new XPathDocument("../../Resources/test5.xml");
                XPathNavigator    navigator  = doc.CreateNavigator();
                XPathExpression   expression = navigator.Compile("/catalog/book");
                XPathNodeIterator iterator   = navigator.Select(expression);

                bookstoreContext = new BookstoreEntities();

                while (iterator.MoveNext())
                {
                    ParseAndSaveBook(bookstoreContext, iterator);
                }
            }
            catch (XPathException xpe)
            {
                Console.WriteLine(xpe.Message);
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
            }
            finally
            {
                if (bookstoreContext != null)
                {
                    bookstoreContext.Dispose();
                }
            }
        }