Exemplo n.º 1
0
        public MainWindow()
        {
            InitializeComponent();

            db = new ChannelContext();

            db.Items.Load();

            DataGrid1.ItemsSource = db.Items.Local.ToBindingList();

            Closing += MainWindow_Closing;

            //using (ChannelContext db = new ChannelContext())
            //{
            //#region try1
            //// создаем два объекта Item
            //Item Item1 = new Item { Title = "test", Link = "test", Description = "test", PubDate = "test" };
            //Item Item2 = new Item { Title = "test2", Link = "test2", Description = "test2", PubDate = "test2" };

            //// добавляем их в бд
            //db.Items.Add(Item1);
            //db.Items.Add(Item2);
            //db.SaveChanges();

            //// получаем объекты из бд и выводим на консоль
            //var Items = db.Items;
            //foreach (Item u in Items)
            //{
            //    textBox1.Text += u.Id + " " + u.Title + " " + u.Link + " " + u.Description + " " + u.PubDate + "\n";
            //}
            //#endregion

            //Channel channel1 = new Channel
            //{
            //    Title = "one",
            //    Description = "one",
            //    Link = "one",
            //    Copyright = "one"
            //};

            //Channel channel2 = new Channel
            //{
            //    Title = "one2",
            //    Description = "one2",
            //    Link = "one2",
            //    Copyright = "one2"
            //};

            //db.Channels.AddRange(new List<Channel> { channel1, channel2 });

            //db.SaveChanges();

            // один к одному
            //ChannelImage ChannelImage1 = new ChannelImage
            //{
            //    Id = channel1.Id,
            //    ImgTitle = "one",
            //    ImgLink = "one",
            //    ImgURL = "one"
            //};

            //ChannelImage ChannelImage2 = new ChannelImage
            //{
            //    Id = channel2.Id,
            //    ImgTitle = "one2",
            //    ImgLink = "one2",
            //    ImgURL = "one2"
            //};

            //db.ChannelImages.AddRange(new List<ChannelImage> { ChannelImage1, ChannelImage2 });
            //db.SaveChanges();

            // вывоооод

            //MessageBox.Show("Ok!");
            //    foreach (Channel ch in  db.Channels.Include("ChannelImages").To
            //{
            //    textBox1.Text += u.Id + " " + u.Title + " " + u.Link + " " + u.Description + " " + u.PubDate + "\n";
            //}
            //}
        }