private void Page_Loaded(object sender, RoutedEventArgs e) { using (var db = new NewBloggingContext()) { Blogs.ItemsSource = db.Blogs.ToList(); } }
private void Add_Click(object sender, RoutedEventArgs e) { using (var db = new NewBloggingContext()) { var blog = new EFCoreModelLibrary.Blog { Url = NewBlogUrl.Text }; db.Blogs.Add(blog); db.SaveChanges(); var db2 = new BloggingContext(); foreach (var item in db2.Blogs) { var Newblog = new EFCoreModelLibrary.Blog { Url = item.Url }; db.Blogs.Add(Newblog); db.SaveChanges(); } //var blog2 = new EFCoreModelLibrary.Blog { Url = NewBlogUrl.Text+"DB1" }; //db2.Blogs.Add(blog2); //db2.SaveChanges(); ObservableCollection <EFCoreModelLibrary.Blog> list = new ObservableCollection <EFCoreModelLibrary.Blog>(db.Blogs.ToList()); //foreach(var item in db2.Blogs.ToList()) //{ // list.Add(item); //} Blogs.ItemsSource = list; } }
/// <summary> /// Initializes the singleton application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). /// </summary> public App() { this.InitializeComponent(); this.Suspending += OnSuspending; using (var db = new NewBloggingContext()) { db.Database.Migrate(); } //DataAccess.InitializeDatabase(); }