title: Converting IQueryable to ObservableCollection, must know how
body: <p>The question is why does the null reference occur for the observable collection? The error occurs when I try to add item to the obscollection.</p>
  
  <p>Note: I have to know how to give all items present in datagrid to observable collection.</p>
  
  <p>Error:</p>
  
  <blockquote>
    <p>Object reference not set to an instance of an object.</p>
  </blockquote>
  
  <p>line:- "good.Add(temp_table);" in button one click</p>
  
  <h2>.xaml.cs</h2>
  
  <pre><code>Web.DomainService1 oservice = new Web.DomainService1();
  public static ObservableCollection&lt;Web.EMP_TABLE&gt; good = new ObservableCollection&lt;Web.EMP_TABLE&gt;();
  
  public Home()
  {
      InitializeComponent();
      this.Title = ApplicationStrings.HomePageTitle;
  
      EntityQuery&lt;Web.EMP_TABLE&gt; q = oservice.GetEMP_TABLE_OBVQuery();
      LoadOperation&lt;Web.EMP_TABLE&gt; l = oservice.Load(q);
      dataGrid1.ItemsSource = l.Entities;
  }
  
  
  
  private void button1_Click(object sender, System.Windows.RoutedEventArgs e)
  {
      ObservableCollection&lt;Web.EMP_TABLE&gt; good = 
          dataGrid1.ItemsSource as ObservableCollection&lt;Web.EMP_TABLE&gt;;
      Web.EMP_TABLE temp_table = new Web.EMP_TABLE();
      temp_table.SALARY = "new_sal";
      temp_table.EMP_NAME = "new_name";
      temp_table.EMP_NO = "new_num";
      good.Add(temp_table);
  }
  </code></pre>
  
  <h2>.xaml</h2>
  
  <pre><code>&lt;sdk:DataGrid AutoGenerateColumns="True" Height="116" Name="dataGrid2" Width="539" /&gt;
  </code></pre>
  
  <h2>The DomainService function</h2>
  
  <pre><code>public ObservableCollection&lt;EMP_TABLE&gt; GetEMP_TABLE_OBV()
  {
      var value = from c in this.ObjectContext.EMP_TABLE
                  select c;
      ObservableCollection&lt;EMP_TABLE&gt; result = new ObservableCollection&lt;EMP_TABLE&gt;(value);
      return result;
  }
  </code></pre>