title: Datagrid binding with LINQ results? WPF
body: <p>I am trying to bind(no code behind =)) my datagridview from my example WPF Application with my results of my LINQ. It must be pretty easy but I am missing it "somehow" somewhere. Some things you must consider: First of all I am using an ORACLE db and I have successfully made the mappings, I am having this result:</p>
  
  <pre><code>     this.SearchCommand = new RelayCommand(this.DisplayMessage, CanDisplayMessage);
      }
  
  
      public bool CanDisplayMessage()
      {
          return true;
      }
  
      public void DisplayMessage()
      {
         using ( Entities ctx = new Entities())
          {
              var query = from e in ctx.EMPLOYEES select new { e.EMPLOYEE_ID,e.FIRST_NAME,
                           e.LAST_NAME, e.EMAIL, e.PHONE_NUMBER,
                           e.SALARY, e.DEPARTMENT_ID};
  
           var results = query.ToList();
          }
      }
  </code></pre>
  
  <p><a href="http://s27.postimg.org/ya0crw701/linqresults.jpg" rel="nofollow">http://s27.postimg.org/ya0crw701/linqresults.jpg</a></p>
  
  <p>I know that I have to bind my Datagrid with an Itemssource, as I have always have made it. I used an ObservableCollection to bind my results from my DataReader (with normal Sql Commands...) with my DataGrid. Now my XAML looks like this:</p>
  
  <pre><code>   &lt;DataGrid Grid.Row="1" Grid.ColumnSpan="3" ItemsSource="{Binding}" &gt;
          &lt;DataGrid.Columns&gt;
          &lt;DataGridTextColumn Header="Employee ID"    Binding="{Binding Path= EMPLOYEE_ID}"/&gt; 
          &lt;DataGridTextColumn Header="First Name"     Binding="{Binding Path= FIRST_NAME}"/&gt;
          &lt;DataGridTextColumn Header="Last Name"      Binding="{Binding Path= LAST_NUMBER}"  /&gt;
          &lt;DataGridTextColumn Header="Email"          Binding="{Binding Path= EMAIL}"  /&gt;
          &lt;DataGridTextColumn Header="Phone number"   Binding="{Binding Path= PHONE_NUMBER}"/&gt;
          &lt;DataGridTextColumn Header="Salary"         Binding="{Binding Path= SALARY}"  /&gt;
          &lt;DataGridTextColumn Header="Department ID"  Binding="{Binding Path= DEPARTMENT_ID}"  /&gt;
          &lt;/DataGrid.Columns&gt;
      &lt;/DataGrid&gt;
  </code></pre>
  
  <p><a href="http://s29.postimg.org/or9jhxuau/xaml.jpg" rel="nofollow">http://s29.postimg.org/or9jhxuau/xaml.jpg</a></p>
  
  <p>I have tried to bind my Results from my LINQ:</p>
  
  <pre><code>  public void DisplayMessage()
      {
         using ( Entities ctx = new Entities())
          {
              var query = from e in ctx.EMPLOYEES select new { e.EMPLOYEE_ID,e.FIRST_NAME,
                           e.LAST_NAME, e.EMAIL, e.PHONE_NUMBER,
                           e.SALARY, e.DEPARTMENT_ID};
  
           var results = query.ToList();
  
          }
      }
  </code></pre>
  
  <p>with my datagrid but nothing is coming back! I have tried to bind an Observerable Collection with this result but I am having an Error. What I am missing here? What I have to write on ItemsSource of my DataGrid so I can bind the the Datagrid with my results?</p>
  
  <p>Thanks in advance!</p>