1

Recently i install VS2012 and Try remake my old WPF project. In VS2010 that code work and all updated or new rows in Datagrid saved in DB via Entity Model. In VS2012 new rows not being added in Database.

    MyEntities context = new MyEntities();

    public MainWindow()
    {
        InitializeComponent();

    }

    private void Button_Click_1(object sender, RoutedEventArgs e)
    {
        var selected = from row in context.Sources
                       select row;
        Datagrid.ItemsSource = selected.ToList();
    }

    private void Button_Click_2(object sender, RoutedEventArgs e)
    {
        context.SaveChanges();
    }

Why is new rows not being added?

Roman G.
  • 182
  • 12
  • if you put the breakpoint at the end of the `Button_Click_1` function, what did you see at `Datagrid.ItemsSource`? Is it correctly assigned? – Gianni B. Oct 22 '12 at 09:45
  • have you tried something [like this](http://stackoverflow.com/questions/7059070/why-does-the-datagrid-not-update-when-the-itemssource-is-changed)? – Gianni B. Oct 22 '12 at 12:16
  • [Here](http://stackoverflow.com/questions/7059070/why-does-the-datagrid-not-update-when-the-itemssource-is-changed) said how update DataGrid. I need answer on: how update Database via Entity. In VS 2010 i only make Something like Datagrid.ItemsSource=context.Table1.ToList(); and do what want with DataGrid(make new rows, update rows e.t.c.), after i call context.SaveChanges(); and all changes have been saved in Database. So why identical code working in different ways in VS2010 and VS2012. – Roman G. Oct 22 '12 at 12:39

0 Answers0