title: WPF Linq to SQL Returning a Custom Object with Data Binding to DataGrid C# MVVM
body: <p>I am trying to make the jump from WinForms to WPF and I'm trying to learn the correct way. I want to use a correct MVVM model. This is my first WPF project ever and I am having trouble with databinding with a linq result. I am aware that I could do this very easily in the code behind or even not use a custom object and return entire table form the linq query to the datagrid while still using a separate class. But I would like to stick to this format. I don't want to use a datatable.</p>
  
  <p>Assume that I have a dbml with a "Job" table. I want to select columns "Job" (Linq seems to automatically rename this column to Job1), "Customer", and "Order_Date".</p>
  
  <p>Here is my code:</p>
  
  <pre><code>namespace Custom_Teplate.Model
  {
      public class LINQResult 
      {
          public System.String JobNum
          { get; set; }
          public System.String CustomerName
          { get; set; }
          public System.DateTime Order_Date
          {get; set; }
  
          public static LINQResult Create()
          {
              DataDataContext dc = new DataDataContext();
              dynamic query = (from ddd in dc.Jobs
                               where (ddd.Status == "Active")
                               select new LINQResult
                               {
                                   JobNum = ddd.Job1,
                                   CustomerName = ddd.Customer,
                                   Order_Date = ddd.Order_Date,   
                               });
             return query;
          }
      }
  }
  </code></pre>
  
  <p>I add the namespace to my XMAL:</p>
  
  <pre><code>xmlns:c="clr-namespace:Custom_Teplate.Model"
  &lt;Window.Resources&gt;
      &lt;c:LINQResult x:Key="ResultListData" /&gt;
  &lt;/Window.Resources&gt;
  </code></pre>
  
  <p>and set the itemssource as follows:</p>
  
  <pre><code>ItemsSource="{Binding Source={StaticResource ResultListData}}
  </code></pre>