using System.Linq;
using System.Data.Linq;
using System.ComponentModel;
using System.Collections.ObjectModel;

namespace WPDatabaseEntitySet
{
    public class PersonenDataContext : DataContext, INotifyPropertyChanged
    {
        public static string DBConnectionString = "Data Source=isostore:/PersonenOrder.sdf";

        public PersonenDataContext(string connectionString)
            : base(connectionString)
        {
            if (!DatabaseExists())
            {
                CreateDatabase();
            }

            var personenInDB = from Person person in PersonenTable
                               select person;
            Personen = new ObservableCollection<Person>(personenInDB);
        }

        public Table<Person> PersonenTable;
        public Table<Order> OrderTable;

        private ObservableCollection<Person> personen;
        public ObservableCollection<Person> Personen
        {
            get
            {
                return personen;
            }
            set
            {
                if (personen != value)
                {
                    personen = value;
                    NotifyPropertyChanged("Personen");
                }
            }
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion
    }
}
