using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace WPDatabase2
{
    public partial class MainPage : PhoneApplicationPage
    {
        private PersonenDataContext personenDataContext;
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            personenDataContext = new PersonenDataContext(PersonenDataContext.DBConnectionString);
            this.DataContext = personenDataContext;
            Person person = new Person()
            {
                FirstName = "Simon",
                LastName = "Hackfort",
                Age = 32,
                City = "Duisburg"
            };
            Order order = new Order()
            {
                Name = "Programmieren für WP7"
            };
            person.Order = order;
            personenDataContext.PersonenTable.InsertOnSubmit(person);
            personenDataContext.SubmitChanges();

            var personFromDB = (from Person p in personenDataContext.PersonenTable
                                select p).Single();

            personenDataContext.PersonenTable.DeleteOnSubmit(personFromDB);
            //personenDataContext.OrderTable.DeleteOnSubmit(personFromDB.Order);
            personenDataContext.SubmitChanges();
            var personFromDBCount = (from Person p in personenDataContext.PersonenTable
                            select p).Count();
            var orderFromDBCount = (from Order o in personenDataContext.OrderTable
                            select o).Count();
        }
    }
}